Skip to content

Commit 677cd70

Browse files
committed
Basic support for @tags (suggested by Jonathan Reeve)
1 parent 7a9e923 commit 677cd70

File tree

6 files changed

+62
-11
lines changed

6 files changed

+62
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The notes.vim plug-in for the [Vim text editor] [vim] makes it easy to manage yo
77
* **Editing existing notes:** Execute `:Note anything` to edit a note containing `anything` in its title (if no notes are found a new one is created with its title set to `anything`)
88
* **Deleting notes:** The `:DeleteNote` command enables you to delete the current note
99
* **Searching notes:** `:SearchNotes keyword …` searches for keywords and `:SearchNotes /pattern/` searches for regular expressions
10+
* **Smart defaults:** Without an argument `:SearchNotes` searches for the word under the cursor (if the word starts with `@` that character will be included in the search, this means you can easily search for *@tagged* notes)
1011
* **Back-references:** The `:RelatedNotes` command find all notes referencing the current file
1112
* A [Python 2] [python] script is included that accelerates keyword searches using an [SQLite] [sqlite] database
1213
* **Navigating between notes:** The included file type plug-in redefines [gf] [gf] to jump between notes and the syntax script highlights note names as hyper links

autoload/xolox/notes.vim

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: May 22, 2011
3+
" Last Change: June 4, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Note: This file is encoded in UTF-8 including a byte order mark so
@@ -169,17 +169,25 @@ function! xolox#notes#delete(bang) " {{{1
169169
endfunction
170170

171171
function! xolox#notes#search(bang, input) " {{{1
172-
" Search all notes for the pattern or keywords {input}.
173-
if a:input =~ '^/.\+/$'
174-
call s:internal_search(a:bang, a:input, '', '')
172+
" Search all notes for the pattern or keywords {input} (current word if none given).
173+
let input = a:input
174+
if input == ''
175+
let input = s:tag_under_cursor()
176+
if input == ''
177+
call xolox#misc#msg#warn("No string under cursor")
178+
return
179+
endif
180+
endif
181+
if input =~ '^/.\+/$'
182+
call s:internal_search(a:bang, input, '', '')
175183
if &buftype == 'quickfix'
176-
let w:quickfix_title = 'Notes matching the pattern ' . a:input
184+
let w:quickfix_title = 'Notes matching the pattern ' . input
177185
endif
178186
else
179-
let keywords = split(a:input)
187+
let keywords = split(input)
180188
let all_keywords = s:match_all_keywords(keywords)
181189
let any_keyword = s:match_any_keyword(keywords)
182-
call s:internal_search(a:bang, all_keywords, a:input, any_keyword)
190+
call s:internal_search(a:bang, all_keywords, input, any_keyword)
183191
if &buftype == 'quickfix'
184192
call map(keywords, '"`" . v:val . "''"')
185193
let w:quickfix_title = printf('Notes containing the word%s %s', len(keywords) == 1 ? '' : 's',
@@ -188,6 +196,16 @@ function! xolox#notes#search(bang, input) " {{{1
188196
endif
189197
endfunction
190198

199+
function! s:tag_under_cursor() " {{{2
200+
try
201+
let isk_save = &isk
202+
set iskeyword+=@-@
203+
return expand('<cword>')
204+
finally
205+
let &isk = isk_save
206+
endtry
207+
endfunction
208+
191209
function! s:match_all_keywords(keywords) " {{{2
192210
" Create a regex that matches when a file contains all {keywords}.
193211
let results = copy(a:keywords)

doc/notes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ notes in Vim:
2121
- Searching notes: ':SearchNotes keyword …' searches for keywords and
2222
':SearchNotes /pattern/' searches for regular expressions
2323

24+
- Smart defaults: Without an argument ':SearchNotes' searches for the word
25+
under the cursor (if the word starts with '@' that character will be
26+
included in the search, this means you can easily search for @tagged notes)
27+
2428
- Back-references: The ':RelatedNotes' command find all notes referencing the
2529
current file
2630

misc/notes/shadow/Note taking commands

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ notes containing all of the given keywords:
3838

3939
:SearchNotes syntax highlighting
4040

41+
## :SearchNotes understands @tags
42+
43+
If you don’t pass any arguments to the :SearchNotes command it will search for
44+
the word under the cursor. If the word under the cursor starts with ‘@’ this
45+
character will be included in the search, which makes it possible to easily
46+
add @tags to your @notes and then search for those tags. To make searching for
47+
tags even easier you can create key mappings for the :SearchNotes command:
48+
{{{vim
49+
" Make the C-] combination search for @tags:
50+
imap <C-]> <C-o>:SearchNotes<CR>
51+
nmap <C-]> :SearchNotes<CR>
52+
53+
" Make double mouse click search for @tags. This is actually quite a lot of
54+
" fun if you don’t use the mouse for text selections anyway; you can click
55+
" between notes as if you’re in a web browser:
56+
imap <2-LeftMouse> <C-o>:SearchNotes<CR>
57+
nmap <2-LeftMouse> :SearchNotes<CR>
58+
}}}
59+
These mappings are currently not enabled by default because they conflict with
60+
already useful key mappings, but if you have any suggestions for alternatives
61+
feel free to contact me through GitHub or at peter@peterodding.com.
62+
63+
## Accelerated searching with Python and SQLite
64+
4165
After collecting a fair amount of notes (say >= 5 MB) you will probably start
4266
to get annoyed at how long it takes Vim to search through all of your notes. To
4367
make searching more scalable the notes plug-in includes a Python script which

plugin/notes.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
" Vim plug-in
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: May 22, 2011
3+
" Last Change: June 4, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55
" License: MIT
6-
" Version: 0.8.7
6+
" Version: 0.8.8
77

88
" Support for automatic update using the GLVS plug-in.
99
" GetLatestVimScripts: 3375 1 :AutoInstall: notes.zip
@@ -39,7 +39,7 @@ endif
3939
" User commands to create, delete and search notes.
4040
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#complete Note call xolox#notes#edit(<q-bang>, <q-args>)
4141
command! -bar -bang DeleteNote call xolox#notes#delete(<q-bang>)
42-
command! -bar -bang -nargs=1 SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
42+
command! -bar -bang -nargs=? SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
4343
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
4444

4545
" Automatic commands to enable the :edit note:… shortcut and load the notes file type.

syntax/notes.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim syntax script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: May 22, 2011
3+
" Last Change: June 4, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Note: This file is encoded in UTF-8 including a byte order mark so
@@ -27,6 +27,10 @@ call xolox#notes#highlight_names(1)
2727
syntax cluster notesInline add=notesName
2828
highlight def link notesName Underlined
2929

30+
" Highlight @tags as hyperlinks. {{{2
31+
syntax match notesTagName /\(^\|\s\)\@<=@\w\+/
32+
highlight def link notesTagName Underlined
33+
3034
" Highlight list bullets and numbers. {{{2
3135
syntax match notesListBullet /^\s*\zs\(\|\*\)/
3236
highlight def link notesListBullet Comment

0 commit comments

Comments
 (0)