I want to highlight all words that have been matched in another syntax region. Using something similar to regex capture groups, for example given a file:

{highlightme} asda asasd asd asd as hightlightme asd adsasd asd
asdaskj highlightme weqeqw (highlightme) {highlightme}

I want to be able to highlight all highlightme IF any one of the highlightme is surrounded with curly braces. What I have so far:

syntax region testSurr start=/{/ end=/}/ contains=testKey nextgroup=testAfter
syntax match testKey /\v\w+/ contained
syntax region testAfter start=/\v\_.*/ end=/\v\_.*/ contained contains=testKey

This works. It highlights all instances of a word if that word is ever matched in a curly brace. However, it also clears the highlighting of everything else in the file. How can I achieve the same result, but preserve the highlighting of everything else?

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.