I'm trying to add this rule:

syn match Keyword /{+.*+}/

If I open a plain text file and run the above as a command, it works: stuff like {+ asdf +} gets highlighted as a keyword.

However, if I add this to a syntax file, or I run this after opening a syntax-highlighted file such as a Git diff, it does nothing. Try as I might, I can't get it to highlight the matched parts.

If I do :sy clear in a Git diff file and add the match rule as a command, it works. Is something in the existing syntax definition perhaps preventing further rules from working/being added?

I can see (using this mapping) that the text I'm trying to highlight is not currently part of any syntax item—in other words, the text is the default text colour not because it is assigned that way, but because it is assigned to nothing at all.

For what it's worth, I'm using MacVim, which seems to have a built-in Git syntax definition that is loaded after all my other syntax files—not that editing that file makes any difference here. I just tried this with NeoVim as well, with no success.


The problem was a broken syn region. The pattern for that region was matching some but not all of the correct regions. Therefore adding my rule and specifying the containing region would highlight the matched regions only, whereas not specifying the containing region would highlight the unmatched regions only.

The solution is to fix the region matching.

Your Answer

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

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