Ignore match in certain syntax groups (e.g. C defines)
Hello! Firstly, thank you for this plugin - I've been using it extensively!
I have a problem for which I didn't find plausible solution after searching through this repository.
To be precise, I want to disable matching parentheses, curly brackets, etc within C define commands.
The reason for this behavior is that rainbow's own highlights will break vim syntax highlights (this is especially apparent in multi-line defines) as seen in example image below
| Current behavior |
|---|
I want to keep highlights for all pairs of parentheses, brackets, etc while not matching ones in define statements. Example of desired behavior can be seen on image below
| Desired behavior |
|---|
Can this be achieved just through configuration, or alternatively, a patch I can apply for this plugin? Just as a note, I don't wish to completely disable matching for C filetype.
Vim shows that C defines have highlight group cDefine which (I think) is a link to Define group
I made a temporary solution with the following match patterns:
let g:rainbow_conf.separately['c'] = { 'parentheses': [
\ 'start=/\%(.*\\\)\@!\%(#.*\)\@<!{/ end=/}/ fold',
\ 'start=/\%(.*\\\)\@!\%(#.*\)\@<!(/ end=/)/ fold',
\ 'start=/\%(.*\\\)\@!\%(#.*\)\@<!\[/ end=/\]/ fold',
\ ]
\}
See :h @<! and :h @!
IMO, It's not even half good:
- The set of
operatorsinrainbowconfiguration will be highlighted insidedefinestatement (note the&&operators); - The last line of multi-line
defineis still going to be matched; - This affects how all parentheses, brackets, etc in file are interpreted, and is probably slower.
| After applying new pattern |
|---|
I think this should really be done with some kind of Vim syntax exclusion (i.e., if {start|end} not in group), but I have no idea how to do it right now.
The :syntax command shows the syntax rule about cDefine is:
cDefine xxx start=/^\s*\zs\%(%:\|#\)\s*\%(define\|undef\)\>/ skip=/\\$/ end=/$
/ keepend contains=ALLBUT,@cPreProcGroup,@Spell
links to Macro
and the top level rainbow rules is
cRainbow_lv0_r0 xxx matchgroup=cRainbow_lv0_p0 start=/(/ end=/)/ fold contains=TOP,@
NoSpell containedin=@cRainbowRegions_lv3
matchgroup=cRainbow_lv0_p0 start=/(/ end=/)/ fold contains=TOP,@N
oSpell containedin=@cRainbowRegions_lv3
I'm not sure how to solve this yet, but that might help.