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.

1
  • 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. Dec 9, 2011 at 20:21

1 Answer 1

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.

4
  • 1
    I keep seeing \1\2 instead of \l\2 (mistaking L for one).
    – idbrii
    Dec 8, 2011 at 0:32
  • Unfortunately this isn't working for me. Is there something else I'm missing? If I had a fresh vimrc what should be there? Dec 8, 2011 at 16:55
  • You still need your line "hi def link myTodo Todo", and as pydave notes, it's a lower-case "L", not a number "1". Dec 8, 2011 at 17:09
  • As explained in the updated question, that's what I have to no avail. Dec 9, 2011 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.