Tip #269: Syntax highlighting is "out of sync", seems to correct itself with refresh ??
tip karma |
Rating 33/12, Viewed by 866
|
created: |
|
June 28, 2002 5:21 |
|
complexity: |
|
basic |
author: |
|
Douglas Potts |
|
as of Vim: |
|
5.7 |
This one has come across the 'vim' users mailing list many times, and probably
comp.editors as well...
Summary:
see :help :syn-sync
and search for 'sync' in your favorite syntax file in $VIMRUNTIME/syntax
Long Version:
The syntax highlight code utilizes a certain synchronization method to efficiently
figure out syntax highlighting, specifically if you aren't at the very beginning or
end of a file. The specific setting is 'syntax sync'. For various file types the
method is set by default in this is setup in the syntax file and one can vary
the degree of trouble which VIM goes to to try and figure this out. As an example
for C, from $VIMRUNTIME/syntax/c.vim:
if exists("c_minlines")
let b:c_minlines = c_minlines
else
if !exists("c_no_if0")
let b:c_minlines = 50 " #if 0 constructs can be long
else
let b:c_minlines = 15 " mostly for () constructs
endif
endif
exec "syn sync ccomment cComment minlines=" . b:c_minlines
Where c_minlines is the minimum number of lines that VIM goes backward
to try to find the start of a comment for syntax highlighting. If that line which
starts a comment is outside of that range, highlighting will appear wrong.
You can easily set up something like this in your .vimrc:
let c_minlines=500
or even bigger, but realize that it is a performance trade-off and that
syntax highlighting will slow things down.
<<Get cursor position as byte percentage instead of line percentage |
Insert a single character >>
Additional Notes
|