30 July 2013

Disable syntax driven LaTeX folding in Vim if you edit big .tex files.

I've just spent about half an hour trying to figure out why Vim was being so slow when I was editing a large LaTeX file with syntax highlighting switched on.

syntax on

is probably a regular in most folks' .vimrc files. I got to editing quite a large file today (a journal article submission), and for some reason Vim was so slow, it was taking a second or two every time I hit a key in insert mode, before displaying the character on the screen.

I managed to figure out pretty quickly that If I turned off syntax highlighting, it would speed up again, but that's hardly a permanent solution.

There are a few discussions online about syntax highlighting being expensive on slow machines, and how to get Vim to not process the whole file every time something changes, but they didn't seem to help. Also, despite Vim getting a new and improved regex engine in 7.4, I couldn't believe that my 7.3.somelargenumber could be /that/ bad.

Anyway, after a bit of debugging, I discovered that the culprit is syntax driven folds. Commenting out this line, which was sitting in my vimrc, did the trick:

let g:tex_fold_enabled = 1

Okay, I lose clever folds, but I didn't really use them anyway.

Categories: All articles Vim LaTeX