Vim syntax highlighting with $ and lstlisting's lstinline

Viewed 5898

If I use the inline version of lstlisting as shown:

\lstinline{!$omp parallel for}

the syntax highlighting in vim goes wrong, and the remainder of the latex file is coloured red as if it is all part of the code listing. It's the dollar $ which causes the problem. How can I avoid this?

8 Answers

Based on timss' answer, create a file named ~/.vim/after/syntax/tex/listings.tex and add the following rule. Replace YOURENV with the environment you want to make the highlighting exception for!

syn region texZone start="\\begin{YOURENV}" end="\\end{YOURENV}\|%stopzone\>"

This rule should now automatically be loaded next time you open Vim with an existing .tex file.

screenshot of the highlighting before and after adding the rule

Related