How to set curly braces'/parentheses'/square brackets'/arithmetic operators' syntax highlight color in VIM?

荒凉一梦 提交于 2019-12-07 05:17:32

问题


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.


回答1:


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



回答2:


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

 ...



回答3:


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...




回答4:


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


来源:https://stackoverflow.com/questions/719476/how-to-set-curly-braces-parentheses-square-brackets-arithmetic-operators-syn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!