Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim randomly breaks syntax highlighting

When working on a remote server with rather large ping times, the syntax highlighting suddenly and seeming randomly breaks. When that happens, it looks like this:

enter image description here

The syntax highlighting is fine til line 24, after that everything is grey. I can fix it by randomly scrolling around or close open vim. But I can neither reproduce the problem, nor reproduce the fix.

This does not happen when I work with exactly the same version of vim and exactly the same .vimrc. Therefore I suspect there's something wrong on the server. Especially I suspect the problem might arise due to the long ping times (~ 170 ms).

Did anyone see a similar behaviour?

like image 720
pfnuesel Avatar asked Dec 01 '14 18:12

pfnuesel


1 Answers

I have had this behaviour occasionally, but I've always just let it be, as its only affected me while editing very large files.

However, now you've brought it up I went looking for a solution. I found this page: http://vim.wikia.com/wiki/Fix_syntax_highlighting, which has the following command:

:syntax sync fromstart 

Running that solves it for me, although it does take a while to complete.

Edit: Following that page's suggestion to use minlines argument, I've found that I get instantaneous and usually-correct highlighting by running this command instead:

:syntax sync minlines=20 

But obviously you can play with the value to trade-off speed and accuracy to your own taste.

like image 163
GenericJon Avatar answered Sep 24 '22 02:09

GenericJon