pfnuesel
pfnuesel

Reputation: 15300

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?

Upvotes: 36

Views: 9265

Answers (3)

northtree
northtree

Reputation: 9255

I have the similar issue when paging up/down.

Fixed by this config.

autocmd BufEnter * syntax sync fromstart

Ref: http://vim.wikia.com/wiki/Fix_syntax_highlighting

Upvotes: 17

Frido Emans
Frido Emans

Reputation: 5578

I am not sure this is a solution, I have not been able to find other occurences of this case. I remember seeing something like this once, but I don´t know how to replicate. I suspect that it isn´t the connection though, but something in vim. I miss the beginning of the file to be able to replicate properly.

But you can try different options, like:

:syntax sync ccomment

this is if the beginning of the file is in a c-comment or something; I am not sure if or how this applies to your case; either way, check the docs if there is something useful for you: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-sync

Upvotes: 1

GenericJon
GenericJon

Reputation: 8986

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.

Upvotes: 57

Related Questions