简体   繁体   中英

Vim syntax error highlight

I'm vim newbie, and I been using someone's vim configuration(I've cloned his .vim directory to my home directory).

It seems that his configuration has a bug about syntax checking. As you can see:

在此处输入图片说明

The bracket should not be highlighted, cause there is not error there.

So my question is, which part of the vim configuration should I check for this issue.

Thanks

UPDATE: 0

I think I found the line that cause this bug.

I have a extra.vim file in ~/.vim/syntax/c/extra.vim the file is looks like:

"========================================================
" Highlight All Function
"========================================================
syn match   cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
syn match   cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1

"========================================================
" Highlight All Math Operator
"========================================================
" C math operators
syn match       cMathOperator     display "[-+\*/%=]"
"" C pointer operators
syn match       cPointerOperator  display "->\|\."
"" C logical   operators - boolean results
syn match       cLogicalOperator  display "[!<>]=\="
syn match       cLogicalOperator  display "=="
"" C bit operators
syn match       cBinaryOperator   display "\(&\||\|\^\|<<\|>>\)=\="
syn match       cBinaryOperator   display "\~"
syn match       cBinaryOperatorError display "\~="
"" More C logical operators - highlight in preference to binary
syn match       cLogicalOperator  display "&&\|||"
syn match       cLogicalOperatorError display "\(&&\|||\)="

" Math Operator
hi def link cMathOperator            cOperator
hi def link cPointerOperator         cOperator
hi def link cLogicalOperator         cOperator
hi def link cBinaryOperator          cOperator
hi def link cBinaryOperatorError     cOperator
hi def link cLogicalOperator         cOperator
hi def link cLogicalOperatorError    cOperator


hi def link cFunction Function
hi def link cOperator Operator

" hi Operator guifg=LightGoldenrod

When I comment out the line below:

syn match       cMathOperator     display "[-+\*/%=]"

The issue is gone.

So how can I fix this, and why ?

Vim probably has not checked the entire file. It is a kind of optimization which sometimes fails.

Usually scrolling the file backwards and forwards a couple of screens solves the problem.

You can also force a analysis on the entire file:

:syn sync fromstart

For more information, check Vim FAQ 24.8: Vim syntax highlighting is broken. When I am editing a file, some parts of the file is not syntax highlighted or syntax highlighted incorrectly.

OK, This Bug is corrected with:

-"syn match       cMathOperator     display "[-+\*/%=]"
+syn match cMathOperator display "[-+/*/%=]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM