Tip 100Collect TODO Items in a Register

Combining the :global and :yank commands allows us to collect all lines that match a {pattern} in a register.

This excerpt of code contains a couple of comments that lead with “TODO”:

 Markdown.dialects.Gruber = {
  lists: ​function​() {
 // TODO: Cache this regexp for certain depths.
 function​ regex_for_depth(depth) { ​/* implementation */​ }
  },
 "`"​: ​function​ inlineCode( text ) {
 var​ m = text.match( ​/​​(​​`+​​)(([\s\S]​​*​​?)\1)​​/​ );
 if​ ( m && m[2] )
 return​ [ m[1].length + m[2].length ];
 else​ {
 // TODO: No matching end code found - warn!
 return​ [ 1, ​"`"​ ];
  }
  }
 }

Suppose that we wanted to collect all of the TODO items in one place. ...

Get Practical Vim, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.