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?
: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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With