How to set curly braces'/parentheses'/squa

2019-05-02 10:34发布

How do I highlight operators/parentheses/brackets/etc. in VIM? I'm not interested in coloring matching or unmatching parentheses/brackets.

I've tried ":hi cBracket/whatnot guifg=something" and ":hi Operator/cOperator guifg=something" but these don't seem to affect anything.

4条回答
别忘想泡老子
2楼-- · 2019-05-02 10:40

The solution above breaks code folding that's syntax based (because of the rules with {} overriding something previous). I haven't been able to figure out how to get around this...

查看更多
ゆ 、 Hurt°
3楼-- · 2019-05-02 10:53

Put the following in your .vimrc for red colored (), {}

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

You can do the same for squared brackets, but you need to escape the bracket characters, put the following in your .vimrc for colored []

autocmd BufRead,BufNewFile * syn match brack /[\[\]]/ | hi brack ctermfg=red
查看更多
乱世女痞
4楼-- · 2019-05-02 10:56

There are two parts to Vim syntax coloring: the syn command and the hi command.

As far as I understand, you use syn to define syntax. For example:

syn match parens /[(){}]/

Then you use hi to tell Vim how to highlight parens:

hi parens ctermfg=red
查看更多
成全新的幸福
5楼-- · 2019-05-02 11:04

See :h pi_paren.txt about highlighting matching parens:

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

 ...
查看更多
登录 后发表回答