I am having an issue, which I was able to reduce to the following sequence of commands:

setf c
syntax region templatyExpression matchgroup=Special start='{{' end='}}'
syntax region templatyStatement matchgroup=Special start='{%' end='%}'
syntax match templatyIdentifier '\v[a-zA-Z][a-zA-Z0-9]*' contained containedin=templatyStatement,templatyExpression

From the moment I type the last command, the following C code is improperly highlighted in a test file:

#define FOO 1
mdddddd ddd n

Where m stands for macro-coloured highlighting, d for default highlighting and n for the highlighting associated with numbers.

My question is: why is that? From what I have understood, contained, together with containedin, should only apply the highlighter when within something like {{ foo }} and leave everything else untouched. The rest of my highlighting code works as expected. Is there something obvious I'm missing?


1 Answer 1


There is contains=CONTAINED you can define for regions. See :h syn-contains.

        If the first item in the contains list is "CONTAINED", then
        all groups will be accepted that have the "contained"

So it means that no matter if you specified contained containedin=GROUP to be contained in GROUP it would also be contained in every other regions that have contains=CONTAINED or contains=ALL

  • Aah now I get it! Thank you so much for answering this! Will try it out now and see if I can find a workaround.
    – samvv
    Commented Feb 1, 2020 at 11:57
  • It works! Thank you so much for helping out, I was gradually losing my mind on this one.
    – samvv
    Commented Feb 1, 2020 at 12:07

Your Answer

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

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