I like htmldjango.vim syntax highlighting except for a few things.

1) It highlights all variables (whatever starts with {{ or {% and ends with }} or %}) white and gives it a red font. I want all variables to just he yellow.

2) It colours all opening tags (< and >) yellow and all ending tags (< / and >) red. I want them both to just be blue.

3) In the < head > tag, it highlights all indents with white for some reason. I don't want it to do that.

4) it underlines all the link names. (example: < a href = 'link' > linkName < / a>) I don't want this either.

As you can see, I want to make small changes. I tried opening htmldjango.vim and editing it but I have no idea where it defines the colour of the tags. htmldjango.vim says this

syn cluster djangoBlocks add=djangoTagBlock,djangoVarBlock,djangoComment,djangoComBlock
syn region djangoTagBlock start="{%" end="%}" contains=djangoStatement,djangoFilter,djangoArgument,djangoTagError display containedin=ALLBUT,@djangoBlocks
syn region djangoVarBlock start="{{" end="}}" contains=djangoFilter,djangoArgument,djangoVarError display containedin=ALLBUT,@djangoBlocks
syn region djangoComment start="{%\s*comment\s*%}" end="{%\s*endcomment\s*%}" contains=djangoTodo containedin=ALLBUT,@djangoBlocks
syn region djangoComBlock start="{#" end="#}" contains=djangoTodo containedin=ALLBUT,@djangoBlocks

I'm guessing this is where the tags are defined. But how do I change what the tags are coloured and what not? I even tried opening html.vim and reading through that and it seems that even in html.vim it doesn't define the actual colours (I couldn't find the name of any colour or hex code of any colour in neither html.vim or htmldjango.vim). Where is the file which defines the colours of the tags / variables in htmldjango.vim?


First, don't make any changes to the original syntax files! You'll regret this when you update your Vim.

If you need to make additions / adaptations, Vim has a mechanism for that. Just put the additional :syntax commands into ~/.vim/after/syntax/htmldjango.vim (note the use of the after directory), and it'll automatically be included by Vim.

If you don't need to parse any additional syntax, but just change the colors, that's done by the :hi / :HtmlHiLink commands. As htmldjango.vim is just an extension of html.vim, those are found in the latter.

To change the colors, you need to find out which syntax group causes the highlighting. :syn list shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin. When you have the name of the offending syntax group, you can redefine the highlighting, for example:

This is the original definition:

HtmlHiLink htmlTag                     Function
HtmlHiLink htmlEndTag                  Identifier

Apparently, your colorscheme (yet another abstraction) paints Function yellow and Identifier red. To override this just for HTML(Django), you'd pick another group from the plain :hi command's output, choose e.g. Special and then redefine via this:

hi link htmlTag Special
hi link htmlEndTag Special

You can put those into the mentioned ~/.vim/after/syntax/htmldjango.vim, or also just into your ~/.vimrc.

To remove all highlighting from a group, use :hi link htmlGroupHere NONE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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