Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this in my vimrc:

"on will override defaults set.  Enable will allow you to set defaults."
syntax enable


"attempting to highlight specific keywords so it is easy to see in code."
"see help e410 for more info."
syn keyword JakeKeywords        Question TODO Answer JAKEHTTPS
highlight JakeKeywords cterm=bold term=bold ctermbg=black ctermfg=Blue

(Note: for the sake of readability I have finished all quotes)

I have tried inserting the JAKEHTTPS keyword in:

  • .java files
    • in comments
    • in code
  • .xml files
    • in comments
    • in code
  • .jak files (custom format that I created see below)

The only place that the keyword is highlighted is in the .jak.

Question: Why are these keywords NOT being highlighted in java code or xml code (and probably other code as well?


syn region JakeSubtitle start=+==+ end=+==+
highlight JakeSubtitle ctermbg=black ctermfg=DarkMagenta

syn region JakeTitle start=+===+ end=+===+
highlight JakeTitle ctermbg=black ctermfg=yellow

Note: I created this thread but it has become too cluttered to be useful.

share|improve this question
up vote 3 down vote accepted

For standard filetypes the syntax tags are cleared before loading the filetype.vim syntax file
You can see the command,

syntax clear
in the begining of java.vim and xml.vim syntax files
Just change the lines in vimrc as follows,
au bufread * syn keyword JakeKeywords        Question TODO Answer JAKEHTTPS
au bufread * highlight JakeKeywords cterm=bold term=bold ctermbg=black ctermfg=Blue
This should work fine...

share|improve this answer
Oh brilliant! That is a a sweet solution. I have not tried it yet but clearly it will. Does this imply that vimrc is called before the syntax file? Is there somewhere that I can find out what order these files are called? – sixtyfootersdude Mar 4 '10 at 14:59

It may be a matter of the keywords being contained within an overarching region or match area that handles all the highlighting. For example, if these keywords you want highlighted are within a comment region, then the associated syntax file is setting up highlight that applies to the entire comment line and isn't getting overridden by keyword highlighting within the comment. You know this already because comment lines are uniform color and regular keyword highlighting doesn't apply within comments.

To fix the problem above, if it or something like it is your problem, you need to search the java.vim syntax file and make sure the keyword you're trying to highlight is in the 'Contains' clause of the comment region definitions (and/or all other overarching region definitions within which you want the keyword highlighted).

E.g., one comment region in my syntax file for java (java.vim) is this: [code] syn region javaComment start="/*" end="*/" contains=@javaCommentSpecial,javaTodo,@Spell [/code]

You would need to add your keyword 'JakeKeyWords' to the contains clause above if you want those keywords to be highlighted within comment regions. Or just add your new keywords to javaToDo group, which is already set up to show up with special highlighting within comments.

Not sure what you're doing with the JakeSubTitle and JakeTitle regions you're trying to define. Same problem with contains may apply to them. Also, 'syntax match' command is what you want to use to highlight regions that can be matched by a single pattern, 'region' is necessary only for more complex areas (usually multi-line) that can't be matched by a single pattern.

share|improve this answer
Yepp good point. – sixtyfootersdude Mar 4 '10 at 15:00
@sixtyfooters: for some reason I couldn't add comment in the other post in this thread, but the command ':scriptnames' gives a list of scripts that have been sourced (i.e. run) in the current buffer, in order of execution. – user22303 Mar 4 '10 at 17:46

How you set highlight depends on how you are running vim. My guess is you are running gvim in the gui.

Your settings work if you are runing vim in a terminal, but if you are running gvim, then you need to use guibg & guifg. When I use the settings you have above & run the highlight test in gvim, :so $VIMRUNTIME/syntax/hitest.vim, JakeKeywords has no special formatting applied. When I rerun the test, but invoke vim from the command line (I'm in a WindowsXP cmd shell right now), your example JakeKeywords example works great.

When I change

highlight JakeKeywords cterm=bold term=bold ctermbg=black ctermfg=Blue


highlight JakeKeywords gui=bold guibg=black guifg=Blue

then I get blue text on a black background in gvim.

If you want this highlight to be applied both color terminals (like terminator or nautilus) & gvim, you need to set highlight both:

highlight JakeKeywords gui=bold cterm=bold term=bold ctermbg=black \
                       ctermfg=Blue guibg=black guifg=Blue
share|improve this answer
Hi Dave, Thanks for the response. I am running vim on the command line (Solaris, Bash). I don't think that this is the problem because as I described in my description there is highlighting in certain file types (ie ones that vim does not have highlighting for already). – sixtyfootersdude Feb 26 '10 at 14:31
what does the output of hitest look like? – DaveParillo Feb 27 '10 at 6:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .