The syntax plugin for TeX/LaTeX that comes bundled with vim is pretty good, not only does it highlight keywords, markup, environments but allows folding of text using
part/chapter/section/subsection/subsubsection/ and so on. This is a tremendous help for navigating documents.
Enabling LaTeX folding
To enable it, put
% vim: fdm=syntax
to the end of your LaTeX source file (or set it from the command line or add it to your
Vim LaTeX folding is wrong / Vim Latex Syntax Highlighting is wrong
The folding and syntax highlighting reacts badly if you have unmatched parentheses/braces/brackets in the text. If the folding works up to a certain point and then slaps everything together into one big fold or if the
section markup is highlighted like a
Statement instead of like a
texSection — the root of the problem is probably an unclosed parenthesis.
Search for all opening parens
/( and make sure they are closed.
In my case, the problem was a sad smilie face I had in a comment. :-( But I fixed it by adding a happy smilie :-) Oh, if only there were more things in life that could be fixed by adding a happy smilie!
Formatting gets really slow
Unfortunately, when the file is rather large, enabling syntax-based folding makes formatting paragraphs (e.g.
gqap) really slow. I haven’t found a solution for this yet, my workaround is to temporarily
set foldmethod=marker and set it back to
set foldmethod=syntax when I’m not writing text.