1

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?

1 Answer 1

0

late answer but might still be useful for you or others.

You could do:

syn region testregion start='{' end='}' contains=testhi
syn keyword testhi highlightme contained

hi def testhi cterm=italic,bold 

and just don't define a highlighting for the region. Might even add more keywords.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.