4

Starting with vim and love that it highlights todo comments. Around here, however we use a custom keyword (first initial last initial todo: abTODO) so it's easy to grep for todos that apply to a specific person.

I'd love to add mine as a keyword that vi picks up and highlights along with todo, fixme and xxx.

In vim, how do I highlight TODO: and FIXME:? seems to apply, but using the following does not work:

syn match   myTodo   contained   "abTODO"
hi def link myTodo Todo

UPDATE

In my .vimrc I have the following 3 lines (as suggested):

syntax enable
syn match myTodo "\<\l\{2\}TODO\>"
hi def link myTodo Todo

That is a lowercase L, not 1. However abTODO is still not being highlighted at all.

Community
  • 1
  • 1
Gidgidonihah
  • 18,293
  • 4
  • 20
  • 20
  • That's very strange. Do you have a filetype set (`:set ft`)? If so, it might be better to add the lines to the relevant syntax file, or to $HOME/.vim/after/syntax/FILETYPE.vim. – Prince Goulash Dec 09 '11 at 20:21

1 Answers1

3

Try this match:

syn match myTodo "\<\l\{2\}TODO\>"

Explanation:

  • \< matches the beginning of a word
  • \l\{2\} matches precisely two lowercase letters
  • TODO\> matches the string TODO at the end of the word

Your highlight command is fine at it is. I don't think the contained option is necessary here.

Prince Goulash
  • 15,295
  • 2
  • 46
  • 47