After fixing a hard-drive failure, I am installing GVIM on my Thinkpad X230T laptop running Windows 10. Things are working well except for the rending speed of buffers for *.tex
files. The problem is: with syntax on
, the buffer of latex renders exceptionally slow. Here goes a list of "features":
- It takes seconds to refresh a buffer of size 1920*1080 (in pixels) when I press
<C-f>
; - If I shrink the size of the buffer, the rendering gets faster. Still, I shall experience a second lag at minimum. During the lag, I can only see a blank buffer.
- Text operations are also slow. Simply starting a new line below by pressing
o
shall also end up with a one-second-lag. This is largely due to the rendering of the whole buffer after adding that single line: all the lines that follows shall be refreshed for their "new" position.
I have applied all the suggested options mentioned in this post (https://stackoverflow.com/questions/8300982/vim-slow-running-latex-files), yet I still get the same slow rendering speed.
I was only experiencing this exceptional slowdown on my X230T. With exactly the same _vimrc
on the other two desktop machines, I don't even experience a tiny lag in the rendering speed. Nor did I experience the rendering problem with previous installation of Windows 7 and 8 on the same X230T laptop.
Lastly, for hard drive, I am having a SSD on my X230T, which worked pretty well so far; and I have HDD on both the other two desktop machines.
Any advice would be very helpful!
Thanks a lot!
All the best,
-Linfeng
Best Answer
The problem is, vim's regular expression engine is really slow, and I guess latex is pretty demanding on regex.
I was able to get vim a bit faster by doing:
These were the main offending syntax group regexes.
I found them by doing:
Now press
ctrl+L
a ton of times and wait for vim to catch up. Then:This gave the following output:
So you can see that those two regexes are way more expensive than others. I don't use folds, so I had no issue disabling that. Not sure why finding the preamble is so slow.
Perhaps this helps you too, @llinfeng. I hope so!
EDIT:
To run those
syn clear
commands when vim starts, you would need to put them in~/.vim/after/syntax/tex.vim
. It won't work in anftplugin
file, as the syntax definitions are not yet loaded at that point.EDIT2:
Turns out some of the syntax groups I posted above came from a plugin. Disabling the plugin doesn't help, as then some other syntax groups are slow. Eesh!
My final fix, and all I ask from syntax highlight, is:
It's really fast.