开发者

gvim long multiline string highlighting

开发者 https://www.devze.com 2023-03-19 15:06 出处:网络
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 an

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 th开发者_开发知识库e 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


You probably don't want sync fromstart for all types of code you are editing, just html. If that's the case, add this to your vimrc:

autocmd FileType html autocmd BufEnter * :syntax sync fromstart
0

精彩评论

暂无评论...
验证码 换一张
取 消