# Changing the color of delimited text

I am editing text of the form

first line
second line
\note{
first line
second line
}


I have to leave intact the text that's delimited by curly brackets and edit the text that's not delimited. But I keep making mistakes and editing the delimited text and leaving intact the text I meant to edit. A way to fix this would be to some how color everything that's contained in \note{ } Is there a way to do something like this?

This is not too complicated. Try this:

syn match delimited /\\note{\_.\{-}}/ containedin=ALL
hi delimited guifg=red ctermfg=red


Of course, you can change red to whatever color you want.

Note that this does what you asked for, but it might also do much more than what you asked for because you didn't provide a lot of detail about what exactly you want to highlight. For example, look at how this is highlighted:

Is this what you want? Will you have to handle nested brackets? What about when \note doesn't come at the beginning of the line? What about when the closing } isn't by itself?

You can refine this regex to do exactly what you want. For example,

/^\\note{\_.\{-}}\$/


will only match if the line starts with \note and then the later line ends with }.

• And may I also suggest the vim wiki's excellent syntax file tutorial? – Tumbler41 Sep 29 '17 at 19:24
• Thanks @djmcmayhem for this. For some reason I couldn't get it to work, putting your two lines into my .vimrc file. Your .png suggests you are using a vim gui; I'm using vim with an xterm. Would that make a difference? And @Tumbler4, I'm afraid I found the wiki tutorial a bit intimidating. I wish they would add really basic MWE's that one could just plug in and try. – Leo Simon Sep 29 '17 at 21:23
• @LeoSimon Yes, I am using a vim gui. The gui part is covered by the guifg part of my answer, and the terminal part should be covered by the ctermfg part. I'm not sure why that isn't working. Let me boot up my vm and test out some things in xterm. – DJMcMayhem Sep 29 '17 at 21:25
• Hi @DJMcMayhem I've figured out the problem. I've now put the commands in ~/.vim/after/syntax/tex.vim Now try \documentclass{beamer}\note{The 2016 Presidential campaign was notable for its hyperbole} \begin{document} \note{The 2016 Presidential campaign was notable for its hyperbole} \end{document} Highlighting works before the begin{document} command but not after it. Thoughts? – Leo Simon Sep 29 '17 at 22:24
• @LeoSimon That's really strange, because that works fine for me. Both lines are highlighted. Would you like to discuss this further in chat? – DJMcMayhem Sep 29 '17 at 23:25