# Color Stuff Inside Braces in a Desired Way With a Trigger

Suppose I have \frac{stuff}{matter} somewhere in a file I am editing. And I want to change stuff and matter. So at the trigger of a command, I'd like to see the following take place:

stuff gets highlighted in red (say) and matter gets highlighted in blue.

This will help me keep track of whether I am editing away at stuff or matter.

Then, of course, I'd like to trigger a command which disables the highlights.

How can I make this happen?

• I don't understand your question. But at the very basic level, it seems that you want to highlight codes inside braces, but with different colors rather than one. That is possible, though I myself don't know how to do it. I say because of rainbow parenthesis in vim for lisp programs. – klaus May 12 '18 at 7:05
• Yeah I just need to color things inside braces which follow a certain phrase, like frac. Can you please elaborate on rainbow parentheses? – caffeinemachine May 12 '18 at 8:21

You're basically talking about syntax highlighting, a relatively deep topic. In simplest terms, you define syntax matches through patterns and link those matches to highlight groups which define text color.

Just about everything you need to know is in :h syntax. You might want to start with a gentler introduction, though. This is one (though perhaps not ideal...I just have it handy): Basic Syntax Highlighting

I'll admit that I'm not that well versed in this stuff (I keep meaning to spend the time needed to learn it!) And, unfortunately, yours is not a trivial case because you have different highlighting on the same line. That being said here's my crack at it...

syntax region rFrac start="\frac" end="\$" contains=rStuff,rMatter keepend
syntax region rStuff start="{stuff" end="}" contains=rMatter contained keepend
syntax region rMatter start="{matter" end="}" contained
" arbitrarily chosen highlight groups...Error is usually red. :)

• Thanks for answering. Yes, I intended for stuff to be arbitrary things. – caffeinemachine May 12 '18 at 8:40
• You could try start="{[^}]*" in rStuff, for starters. – B Layer May 12 '18 at 8:43