sponsor Vim development Vim logo Vim Book Ad

basic Tip #1431: manage a tasklist of TODO code snippets (e.g. //TODO)

 tip karma   Rating 28/16, Viewed by 2471 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   November 30, 2006 18:29      complexity:   basic
author:   David J Hamilton      as of Vim:  

This tip is inspired by the eclipse task list feature, which automagically populates tasks when you put comments in java code with a prefix of TODO.  Sorry if this duplicates an existing tip, but I found googling for this tricky.

The idea is to create a tag for each todo entry and then create a vim command to list only those tags.  The example will be for java, but you'll see that it ought to work for any language.

Assuming you use ctags to generate your tags file, add the following to ~/.ctags

  --regex-java=/\/\/TODO(.*)/todo\1/

This will cause ctags to create tags for the following code

//TODO djh fix this horrible hack
//TODO djh comment this

with names
  todo djh fix this horrible hack
  todo djh comment this


You can then add the following to ~/.vimrc to create a command that easily lists these.

  command TODO tselect /^todo djh


Note that I'm only interested in TODOs that begin with my initials - you may want to simply use /^todo.  Be careful though! If you have case-insensitivity turned on, you may get false positives for tags of the form 'toDouble'.  This can be fixed by changing your todos to //TODO:

 rate this tip  Life Changing Helpful Unfulfilling 

<< Make tar of all files in vim buffer | File search similar to cmd-t in TextMate >>

Additional Notes

[email protected], November 30, 2006 18:34
To make sure that I give credit where credit is due - the original idea for this came from Earl Barr at UC Davis.  Thanks Earl :-)
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo