Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gvim long multiline string highlighting

I make extensive use of multiline docstrings in my python source code to include doctests. Unfortunately, vim/gvim seems to have a hard time with syntax highlighting, occasionally losing it's place and forgetting that it's in the middle of a string literal, and the highlighting "flips" from string to source and source to string.

I can scroll up to the top and back down again, and vim usually fixes the problem, but sometimes it takes a few tries.

Aside from making my docstrings shorter, Is there a way to help vim keep the highlighting on these long literals in order?

like image 549
SingleNegationElimination Avatar asked Jul 12 '11 21:07

SingleNegationElimination


1 Answers

:syntax syn controls how Vim synchronizes the syntax state that should apply at a particular point in the text (:help syn-sync). For the most accurate sync (but this will slow vim down), try:

autocmd BufEnter * :syntax sync fromstart

Or if you want to sync manually whenever you notice it's wrong, try this command (you could map it to a keyboard shortcut):

:syntax sync fromstart

You might also find minlines useful. From :help syn-sync

If the "minlines={N}" argument is given, the parsing always starts at least that many lines backwards. This can be used if the parsing may take a few lines before it's correct, or when it's not possible to use syncing.

So putting this in your .vimrc might help you:

syntax sync minlines=500

Edit: found this page which has everything you need: http://vim.wikia.com/wiki/Fix_syntax_highlighting

like image 154
PonyEars Avatar answered Oct 14 '22 18:10

PonyEars