Custom vim highlighting

bashsyntax highlightingunixvim

I am editing some xml right now and I have been leaving myself some comments of things to come back to. Like this

<!-- Question: bla bla -->

I am editing with vim right now and I would like vim to highlight Question right now so that I can easily look through my code and find all the places I need to look at. I know I need to add something in my vimrc but I think that I might be searching for the wrong thing.

Update

I tried putting this in my .vimrc but it had no effect:

syn keyword JakeAnnotation      Question

hi JakeAnnotation gui=bold term=bold cterm=bold

Update 2

Actually I can see that what I did before had some effect because when I do this:

:hi

It shows me all of the things that it is highlighting and one of the entries is:

JakeAnnotation xxx term=bold cterm=bold ctermbg=6

(and the xxx is formatted correctly)

This leads me to beleave that I am just not defining Question properly. Does Question need to be on a line by itself?

Update 3

Ok so to user 22303's post I have this working:

highlight MyQuestion cterm=bold term=bold ctermbg=blue ctermfg=black
match MyQuestion /Question/

However I suspect that you are only allowed to have one match per file. Because when I do this:

highlight MyQuestion cterm=bold term=bold ctermbg=blue ctermfg=black
match MyQuestion /Question/
highlight MyRelook cterm=bold term=bold ctermbg=blue ctermfg=black
match MyRelook /Another look/

The first one stops working. (But the second one works).

Best Answer

I think we've been feeding you some answers that aren't quite right. Here's something to try that I tested on my machine.

First, create your own new highlight group:

:highlight MyQuestions guifg=red guibg=green

Now, specify that the highlight group will exist whenever a pattern is matched:

:syntax match MyQuestions /Question/

That should start showing highlight of the text 'Question' on each line that has that text. To expand to show whole line you would change search text to have wildcards matching entire line, something like this:

:syntax match MyQuestions /.*Question.*/

Related Question