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

坚强是说给别人听的谎言 提交于 2019-12-05 09:08:36

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

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

 ...

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

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