我想在vim中为c ++定制语法着色.但是,不幸的是,我仍然找不到braces(){} []和c + c ++/objc/objcpp的运算符+ - /*%的正确名称.任何vim大师谁可以建议我必须'hi'什么名称,以便为所提到的项目设置颜色?
我认为在C代码或衍生语言的vim中没有默认的大括号作为标准(它们只是以纯文本形式突出显示).您可以使用以下内容定义自己的内容:
:syn match Braces display '[{}()\[\]]' :hi Braces guifg=red
或者你可以下载彩虹支架突出显示插件,它为不同级别的缩进提供不同的颜色.另见我对这个问题的回答.
:help :syn-match :help hi
有彩虹支柱荧光笔在行动截图(我的强盗配色方案)这里.
编辑:
为了找出您感兴趣的任何突出显示组,请创建此映射:
:map:echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"
(取自此处).然后,将光标移动到您感兴趣的任何内容上,然后按F3.如果它没有突出显示,Vim将打印:
hi<> trans<> lo<>
如果有一个特定的高亮组,你会得到这样的东西(将光标放在if
关键字上):
hitrans lo
它告诉您高亮组被调用cConditional
,并且它与被调用的组链接(:hi link
)Conditional
.使用彩虹支撑突出显示,你可能得到类似的东西cCurly1
,这意味着它在一个大括号内,但没有额外的突出显示.
编辑2:
可能的运算符匹配器(未经过很好的测试):
let cOperatorList = '[-&|+<>=*/!~]' " A list of symbols that we don't want to immediately precede the operator let cOperatorList .= '\@=]' let cOperatorList .= '\)' let cOperatorList .= '\1\?' " Followed by (optionally) the exact same symbol, so -, --, =, ==, &, && etc let cOperatorList .= '\|' " Next option: let cOperatorList .= '->' " Pointer dereference operator let cOperatorList .= '\|' " Next option: let cOperatorList .= '[-+*/%&^|!]=' " One of the listed symbols followed by an =, e.g. +=, -=, &= etc let cOperatorList .= '\|' " Next option: let cOperatorList .= '[*?,!~%]' " Some simple single character operators let cOperatorList .= '\|' " Next option: let cOperatorList .= '\(' " One of the shift characters: let cOperatorList .= '[<>]' let cOperatorList .= '\)' let cOperatorList .= '\2' " Followed by another identical character, so << or >>... let cOperatorList .= '=' " Followed by =, so <<= or >>=. let cOperatorList .= '\)' " End of the long list of options let cOperatorList .= '[-&|+<>=*/!~]' " The list of symbols that we don't want to follow let cOperatorList .= '\@!' " Negative look-ahead (this and the \@
2> pepper_chico..:得到我的彩虹圆括号改进(它也与运营商打交道):https://github.com/oblitum/rainbow