Reputation: 81
I want to customize syntax highlighting in Vim (GUI version). There is an existing syntax file for my language. I want to add to that syntax highlighting a background colour to each line if that line starts with >
. I figured out that I can basically achieve this by
:syntax match Output /^>.*$/
and adding
:hi Output guibg=LightBlue
to the colourscheme. The background of the text in these Output
lines gets coloured then in light blue, but it overrides the foreground colour as well. So most of the syntax highlighting disappears. How can I keep the foreground syntax highlighting in these lines?
Also: Is there a way to extend the highlighting of the background to the end (right end of the screen) of these lines?
Upvotes: 8
Views: 1032
Reputation: 17350
Here is how to preserve the syntax, I'm matching lines starting with {
:hi Output guibg=LightBlue
:match Output '\%>0v{.*'
Edit: since you want the opposite you need
:match Output '^[^<].*$'
Upvotes: 3
Reputation: 9279
The easiest way to achieve what you're looking for is with the :match
command as Eric Fortis has pointed out.
The only way I know of to achieve this with syntax highlighting will require you to match the entire line as you are currently doing. You will then need to specify, using the contains=...
modifier, which syntax elements can be in your line. I'm also pretty sure these elements will need to have the contained
attribute assigned to them. This way any element found in your line i.e matched by the .*
will preserve it's highlighting.
See :help :syn-contains
for more.
Upvotes: 0