在vim中为c ++着色的大括号和运算符?

gri*_*yvp 11 vim syntax-highlighting

我想在vim中为c ++定制语法着色.但是,不幸的是,我仍然找不到braces(){} []和c + c ++/objc/objcpp的运算符+ - /*%的正确名称.任何vim大师谁可以建议我必须'hi'什么名称,以便为所提到的项目设置颜色?

DrA*_*rAl 28

我认为在C代码或衍生语言的vim中没有默认的大括号作为标准(它们只是以纯文本形式突出显示).您可以使用以下内容定义自己的内容:

:syn match Braces display '[{}()\[\]]'
:hi Braces guifg=red
Run Code Online (Sandbox Code Playgroud)

或者你可以下载彩虹支架突出显示插件,它为不同级别的缩进提供不同的颜色.另见我对这个问题的回答.

:help :syn-match
:help hi
Run Code Online (Sandbox Code Playgroud)

有彩虹支柱荧光笔在行动截图(我的强盗配色方案)这里.

编辑:

为了找出您感兴趣的任何突出显示组,请创建此映射:

:map <F3> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
Run Code Online (Sandbox Code Playgroud)

(取自此处).然后,将光标移动到您感兴趣的任何内容上,然后按F3.如果它没有突出显示,Vim将打印:

hi<> trans<> lo<>
Run Code Online (Sandbox Code Playgroud)

如果有一个特定的高亮组,你会得到这样的东西(将光标放在if关键字上):

hi<cConditional> trans<cConditional> lo<Conditional>
Run Code Online (Sandbox Code Playgroud)

它告诉您高亮组被调用cConditional,并且它与被调用的组链接(:hi link)Conditional.使用彩虹支撑突出显示,你可能得到类似的东西cCurly1,这意味着它在一个大括号内,但没有额外的突出显示.

编辑2:

可能的运算符匹配器(未经过很好的测试):

let cOperatorList  = '[-&|+<>=*/!~]'    " A list of symbols that we don't want to immediately precede the operator
let cOperatorList .= '\@<!'             " Negative look-behind (check that the preceding symbols aren't there)
let cOperatorList .= '\%('              " Beginning of a list of possible operators
let cOperatorList .=     '\('           " First option, the following symbols...
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 \@<! prevent === etc from matching)

exe "syn match cOperator display '" . cOperatorList . "'"

syn match cOperator display ';'
hi link cOperator Operator
Run Code Online (Sandbox Code Playgroud)


pep*_*ico 7

得到我的彩虹圆括号改进(它也与运营商打交道):https://github.com/oblitum/rainbow

这是你可以获得的样本