I'm trying to optimize for my needs the syntax highlighting offered automatically by Vim for Latex. For example by changing colors to my liking or link colors to new commands/environemnts.

After a good morning of googling I found out the following:

  • One should not amend the tex.vim file in the vim app folder (for mac) directly. Instead add a tex.vim file in the folder .vim/after/syntax containing all the desired amendments.
  • This works like a charm to change colors. For instance I can write (in such file): highlight texMathZoneX guifg='#83a598', which changes the colour of text associated to the textMathZoneX group.
  • On the other hand, I could not find a working way to make changes to the groups themselves: below follows an extremely simple example.

MWE: I would like the word red to be written with in white with red background. Eventually I would like all the text within a command \red{this text should be red in Vim} to appear with a red background.

  • Is there a way to create a new group, add it to the list of groups and then define the required colour on that group, so that the settings work also inside the document (and not just above the documentclass command)?

Adding the line :syn match texMathError "red" gives for instance the right result, but only above the header:

enter image description here

1 Answer 1


This works like a charm to change colors

The red flash: ERROR. The syntax is local to buffer (or even to window :h ownsyntax). But the colors are global. So syntax files should do "hi-def-link" at most. Other stuff belongs to colorschemes.

the settings work also inside the document

Going through the text the matches are tried with respect to the current (top of stack) :h :syn-match or :h syn-region. If there's still none found then all matches without :h :syn-contained attribute are tried. But if, say, we are inside "A" then it's everything that mentioned in :h :syn-contains of "A" plus everything that claims to be :h :syn-containedin "A".

So to get into group "A" (after "A" has already been defined without contains=B) the group "B" should declare containedin=A attribute. What is the full list of "A"s that "B" wants to get into, it depends on a particular syntax file. There are also ALL and ALLBUT specials but they should be used with much care.

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.