5

如何突出显示运算符/括号/括号/等。在 VIM 中?我对着色匹配或不匹配的括号/括号不感兴趣。

我试过 ":hi cBracket/whatnot guifg=something" 和 ":hi Operator/cOperator guifg=something" 但这些似乎没有任何影响。

4

4 回答 4

4

Vim 语法着色有两个部分:syn命令和hi命令。

据我了解,您使用syn来定义语法。例如:

syn match parens /[(){}]/

然后你hi用来告诉 Vim 如何突出显示parens

hi parens ctermfg=red
于 2009-04-05T19:12:15.953 回答
3

请参阅 :h pi_paren.txt 关于突出显示匹配的括号:

To disable the plugin after it was loaded use this command: >
    :NoMatchParen
And to enable it again: >
    :DoMatchParen
The highlighting used is MatchParen.  You can specify different colors with
the ":highlight" command.  Example: >
    :hi MatchParen ctermbg=blue guibg=lightblue

 ...
于 2009-05-14T19:49:24.250 回答
0

上面的解决方案破坏了基于语法的代码折叠(因为 {} 覆盖了以前的规则)。我一直无法弄清楚如何解决这个问题......

于 2009-05-14T19:34:32.603 回答
0

将以下内容放入您的 .vimrc 中以获得红色 ()、{}

autocmd BufRead, BufNewFile * syn match parens /[(){}]/ | hi parens ctermfg=red

您可以对方括号执行相同操作,但您需要转义括号字符,将以下内容放入您的 .vimrc 中以获取有色 []

autocmd BufRead,BufNewFile * syn match brack /[\[\]]/ | hi brack ctermfg=red
于 2014-09-01T08:54:59.973 回答