Wikia

Vim Tips Wiki

Changes: Simple programmers TODO list using grep and quickfix

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 21: Line 21:
   
 
<pre>
 
<pre>
imap \q &lt;ESC&gt;i//TODO_ITEM&lt;SPACE&gt;
+
imap \q <Esc>i//TODO_ITEM<SPACE>
map \q i//TODO_ITEM&lt;SPACE&gt;
+
map \q i//TODO_ITEM<SPACE>
imap \w &lt;ESC&gt;:grep --exclude=*~ TODO_ITEM * &lt;CR&gt; :copen &lt;CR&gt;
+
imap \w <Esc>:grep --exclude=*~ TODO_ITEM * <CR> :copen <CR>
map \w :grep --exclude=*~ TODO_ITEM * &lt;CR&gt; :copen &lt;CR&gt;
+
map \w :grep --exclude=*~ TODO_ITEM * <CR> :copen <CR>
 
</pre>
 
</pre>
   
Line 39: Line 39:
 
<pre>
 
<pre>
 
" grep for word under cursor in c/cpp/h-files
 
" grep for word under cursor in c/cpp/h-files
map &lt;F9&gt; &lt;ESC&gt;:exec("grep ".expand("&lt;cword&gt;")." ../*/*.c* ../*/*.h")&lt;CR&gt;
+
map <F9> <Esc>:exec("grep ".expand("<cword>")." ../*/*.c* ../*/*.h")<CR>
   
 
"same as menu entry:
 
"same as menu entry:
22amenu Search.Grep\ for\ word\ under\ cursor &lt;ESC&gt;:exec("grep ".expand("&lt;cword&gt;")." ../*/*.c* ../*/*.h")&lt;CR&gt;
+
22amenu Search.Grep\ for\ word\ under\ cursor <Esc>:exec("grep ".expand("<cword>")." ../*/*.c* ../*/*.h")<CR>
 
</pre>
 
</pre>
   

Latest revision as of 05:43, September 29, 2008

Tip 391 Printable Monobook Previous Next

created December 19, 2002 · complexity basic · author Sean · version 6.0


I use this to maintain a TODO list for projects I am working on. All my projects are pretty small scale with each project stored in it's own directory so this tip was writtten with that in mind. Basically it is two keymappings one which inserts

//TODO_ITEM

leaving Vim in insert mode so you can add a note to help you remember what you wanted to do.

The other mapping uses :grep to search for all occurrences of TODO_ITEM in files in the current directory excluding ~ files and then opens the error window displaying the list of TODO_ITEMs.

imap \q <Esc>i//TODO_ITEM<SPACE>
map \q i//TODO_ITEM<SPACE>
imap \w <Esc>:grep --exclude=*~ TODO_ITEM * <CR> :copen <CR>
map \w :grep --exclude=*~ TODO_ITEM * <CR> :copen <CR>

Change the comment style to suit your language and the lame keymappings to something better.

CommentsEdit

I develop in the same fashion (one project per directory) and developed a program to do exactly this, called devtodo (http://devtodo.sf.net).


Be sure to have 'grepprg=grep -n', because vim needs the line numbers.


You can do this 'quickfix' search for any word under the cursor:

" grep for word under cursor in c/cpp/h-files
map <F9> <Esc>:exec("grep ".expand("<cword>")." ../*/*.c* ../*/*.h")<CR>

"same as menu entry:
22amenu Search.Grep\ for\ word\ under\ cursor <Esc>:exec("grep ".expand("<cword>")." ../*/*.c* ../*/*.h")<CR>

Around Wikia's network

Random Wiki