Taylor Venable wrote:
Hello all,

I'm trying to find a way to add keywords to the Todo highlight group,
such that they are only highlighted when inside a comment.  Reading
through the help files, I thought this would work:

:syntax keyword Todo containedin=Comment contained WARNING NOTE

But unfortunately it doesn't seem to highlight anything at all.
Basically, I want WARNING and NOTE to be highlighted only inside
comments, like TODO and FIXME are by default.

Thanks in advance for any ideas.


1) Did you enter this command at the keyboard, in your vimrc, or in some other script?

2) The name of the "comment" syntax group is different for each language. For instance, it may be vimComment, cComment, htmlComment, cssComment, etc., depending on what kind of file you're editing. (The corresponding _highlight_ groups are all linked to Comment by default, but that can be changed, and IIUC it only applies after all _syntax_ groups have been determined, so I guess you need to use the correct syntax group name).

3) Taking point 2 into account, I guess the right place for your command is in an after-syntax-script; for instance for vimscript:

--- start ~/.vim/after/syntax/vim.vim
syn keyword Todo containedin=vimComment contained WARNING NOTE
--- end

For a more ambitious solution (untested)

autocmd Syntax * syn keyword Todo containedin=<amatch>Comment contained
        \ WARNING NOTE

The above may have to be defined late in your vimrc.



Best regards,
Tony.
--
        GREAT MOMENTS IN AMERICAN HISTORY #21 -- July 30, 1917

On this day, New York City hotel detectives burst in and caught then-
Senator Warren G. Harding in bed with an underage girl.  He bought them
off with a $20 bribe, and later remarked thankfully, "I thought I
wouldn't get out of that under $1000!"  Always one to learn from his
mistakes, in later years President Harding carried on his affairs in a
tiny closet in the White House Cabinet Room while Secret Service men
stood lookout.

Reply via email to