【发布时间】:2023-07-13 02:24:02
【问题描述】:
如何突出显示运算符/括号/方括号/等。在 VIM 中?我对着色匹配或不匹配的括号/括号不感兴趣。
我试过 ":hi cBracket/whatnot guifg=something" 和 ":hi Operator/cOperator guifg=something" 但这些似乎没有任何影响。
【问题讨论】:
标签: vim syntax-highlighting parentheses curly-braces
如何突出显示运算符/括号/方括号/等。在 VIM 中?我对着色匹配或不匹配的括号/括号不感兴趣。
我试过 ":hi cBracket/whatnot guifg=something" 和 ":hi Operator/cOperator guifg=something" 但这些似乎没有任何影响。
【问题讨论】:
标签: vim syntax-highlighting parentheses curly-braces
Vim 语法着色有两个部分:syn 命令和hi 命令。
据我了解,您使用syn 来定义语法。例如:
syn match parens /[(){}]/
然后你用hi告诉Vim如何高亮parens:
hi parens ctermfg=red
【讨论】:
看 :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
...
【讨论】:
上面的解决方案破坏了基于语法的代码折叠(因为 {} 覆盖了以前的规则)。我一直无法弄清楚如何解决这个问题......
【讨论】:
将以下内容放入您的 .vimrc 中以获得红色 ()、{}
autocmd BufRead, BufNewFile * syn match parens /[(){}]/ | hi parens ctermfg=red
你可以对方括号做同样的事情,但你需要对括号字符进行转义,将以下内容放入你的 .vimrc 中以获得彩色 []
autocmd BufRead,BufNewFile * syn match brack /[\[\]]/ | hi brack ctermfg=red
【讨论】: