Reputation: 1162
I want to change the color of the text inside double curly brackets
like this {{ a + b }}, but so far this is the only thing I have been able to achieve:
syn match parens /[{}]/
hi parens ctermfg=red guifg=red
which is not exactly what I want as with it I can just change the color of the brackets and if I try this it doesn't work at all
/{([^}]+)}}/
How can I properly write this?
Upvotes: 0
Views: 311
Reputation: 421
I'm more used to "magic" regex in vim (by adding the \v
prefix) so I will write my example using them but you can easily translate to other types of regex supported by vim (see :help magic
).
If I understand your problem correctly, I think you can achieve what you want with the following rule:
syntax match parens "\v\{\{.{-}\}\}"
highlight parens ctermfg=red guifg=red
This regex matches {{ these sort of syntax }} with any character inside the braces because of the .
. The syntax {-}
is equivalent to *
except that vim tries to match the smallest number of characters between {{ and }}. So that you don't match {{ some }} example {{ text }} but {{ some }} example {{ text }}. You can change the .
if you want to be more specific about what you can match inside {{ and }}.
Upvotes: 2