Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline Comments Syntax Coloring in VIM for TeX Files

To my biggest surprise, the multi-line comment syntax in TeX :

\usepackage{verbatim} 
...
\begin{comment}
    I don't like this line anymore. Please don't print it. 
\end{comment}

is not recognized/dealt with by $VIMRUNTIME/syntax/tex.vim and hence not colored as a comment. Is there a VIM scripting Guru that could have a solution around, as I'm sure a lot of people have been looking for it ?

Thanks

VIM v7.3

like image 996
Bertrand Caron Avatar asked May 07 '13 04:05

Bertrand Caron


2 Answers

A little search on VIM Syntax highlighting helped me write this line of code who does almost the whole work when added to ~/.vim/after/syntax/tex.vim (you may need to create the directory in your ~/.vim directory):

syn region texComment    start="\\begin{comment}"    end="\\end{comment}"

My only problem is that it can't find how to disable the matching if it encounters end-of-file before end of comment environment. Anyone has a work-around ?

NB : This command does not support nesting, which is a good thing since Latex neither and you will most likely have unmatched \end{comment}

like image 179
Bertrand Caron Avatar answered Oct 24 '22 20:10

Bertrand Caron


There are more options how to comment code (see multiline comment), so this is content of mine ~/.vim/after/syntax/tex.vim:

syn region texComment   start="\\begin{comment}"    end="\\end{comment}"
syn region texComment   start="\\iffalse"   end="\\fi"
syn region texComment   start="\\ifx true false"    end="\\fi"
like image 32
pevik Avatar answered Oct 24 '22 19:10

pevik