Vim语法错误突出显示

时间:2015-08-24 12:06:57

标签: vim

我是vim新手,我一直在使用别人的vim配置(我已将他的.vim目录克隆到我的主目录。)

他的配置似乎有一个关于语法检查的错误。如你所见:

enter image description here

不应突出显示括号,因为那里没有错误。

所以我的问题是,我应该检查vim配置的哪一部分来解决这个问题。

由于

更新:0

我想我找到了造成这个错误的行。

我在~/.vim/syntax/c/extra.vim中有一个extra.vim文件,该文件看起来像是:

"========================================================
" 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

当我注释掉下面的一行时:

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

问题已经消失。

那我怎么解决这个问题呢?为什么呢?

1 个答案:

答案 0 :(得分:1)

Vim可能还没有检查整个文件。这是一种有时失败的优化。

通常向后滚动文件并转发几个屏幕可以解决问题。

您还可以对整个文件强制进行分析:

:syn sync fromstart

有关详情,请查看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.

相关问题