Vim Tips Wiki
Advertisement

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Previous TipNext Tip

Tip: #1431 - Manage a tasklist of to-do code snippets

Created: November 30, 2006 18:29 Complexity: basic Author: David J Hamilton Version: n/a Karma: 22/13 Imported from: Tip#1431

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.

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:

Comments

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 :-)

davidjh--AT--gmail.com , November 30, 2006 18:34


Advertisement