Let's finally solve this issue once and for all!
I mailed Charles E. Campbell, the maintainer of tex.vim
, suggesting he'd add highlighting rules for the listings package. However it turns out lacking support for the listings package in tex.vim
is actually intentional. The reasoning can be found :h tex-package
. In short, you're supposed to create your own extended syntax highlighting rules (see bottom of post):
Tex: Want To Highlight More Commands?
LaTeX is a programmable language, and so there are thousands of packages full
of specialized LaTeX commands, syntax, and fonts. If you're using such a
package you'll often wish that the distributed syntax/tex.vim would support
it. However, clearly this is impractical. So please consider using the
techniques in mysyntaxfile-add to extend or modify the highlighting provided
by syntax/tex.vim. Please consider uploading any extensions that you write,
which typically would go in $HOME/after/syntax/tex/[pkgname].vim, to
http://vim.sf.net/.
Personally I think it's a little unfortunate that it's not going to be included, as it surely increases the threshold for the average user to write his or hers LaTeX using Vim. Finding and adding syntax highlighting for lstlisting
, lstinline
etc. isn't too easy. It does not look like it's going to change anytime soon either when looking at this thread.
DevSolar seems to have already found it (and I appreciate the credit!), but Campbell offers a couple of example LaTeX package support vimballs. The first one, lstlisting.vba.gz, includes highlighting rules for lstlisting
and lstinputlisting
. It does however lack lstinline
, which this topic is about.
Finally, here's my listings.vim
resided in $HOME/.vim/after/syntax/tex/
syn region texZone start="\\begin{lstlisting}" end="\\end{lstlisting}\|%stopzone\>"
syn region texZone start="\\lstinputlisting" end="{\s*[a-zA-Z/.0-9_^]\+\s*}"
syn match texInputFile "\\lstinline\s*\(\[.*\]\)\={.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt
-
This seems to be the preferred solution. It does not require one to alter system wide files in /usr/share/vim/..
, you don't have to download and source a vimball or alter environments rather than fixing the syntax highlighting itself. I might into look into releasing this as a simple plugin to make it more accessible.
Lastly, remember to check that you're actually running the tex
filetype and not plaintex
which lacks far too much to be viable. Already posted this in a comment above, but some more information can be found in a ticket I added to LaTeX-Box.
\verb{!$omp}
produces the same result. You can try the newest syntax file from mysite.verizon.net/astronaut/vim/syntax/tex.vim.gz and contact its author Charles E. Campbell, Jr. – Polka