I define four key words and two regions in vim scripts

syn keyword KeywordA A nextgroup=rangeA skipwhite skipnl skipempty
syn keyword KeywordB B contained containedin=rangeA nextgroup=rangeB skipwhite skipnl skipempty
syn keyword KeywordC C contained containedin=rangeA
syn keyword KeywordD D contained containedin=rangeB

syn region rangeA start=+{+ end=+}+ contained transparent
syn region rangeB start=+{+ end=+}+ contained transparent

hi KeywordA ctermfg=blue
hi KeywordB ctermfg=green
hi KeywordC ctermfg=cyan
hi KeywordD ctermfg=red

The keywords A and B has two corresponding regions.

When the file is saved as .cpp

The highlighting result is like this:


Actually, the D is in rangeB, but D is not highlighted.

However, if I change the file extension to .t

the result is what I expect:

enter image description here

Is there any solution that I can highlight C and D in rangeB in a cpp file? (Since C in rangeB is also in rangeA)

Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.