VIM – How to change color of if, else, endif, for and endfor statements

djangohtmlsyntax highlightingvim

I just Django html so I have the normal html tags as well as the if, else, endif, for and endfor statements. I use a customized version of the colorscheme called slate. There is a line in the colorscheme which says this:

:hi Statement guifg=CornflowerBlue ctermfg=lightblue

and it turns all html tags and if, else, endif, for and endfor statements to a cornflowerBlue color. How do I make the color of the if, else, endif, for and endfor statements a different color than the html tags?

Best Answer

The corresponding highlight links are these:

from syntax/django.vim:

HiLink djangoStatement Statement

from syntax/html.vim:

HtmlHiLink htmlTagName                 htmlStatement
HtmlHiLink htmlStatement          Statement

You see that both end up linking to the Statement group defined in your colorscheme, and colored blue in your case.

To change those, pick highlight groups from your colorscheme (e.g. Special and Constant), and redefine the links in your ~/.vimrc:

highlight link htmlTagName Special
highlight link djangoStatement Contant

The hidden magic of the HiLink command (which is just a wrapper for :hi def link) is that when a link exists (like with the above two lines), the default won't be activated.

Alternatively, you could also define new colors on the spot (but it's best centralized in a colorscheme):

highlight htmlTagName ctermfg=Cyan guifg=Cyan
Related Question