Consider a simple text markup language where _underscores denote italics_
and *astrisks denote bold*
.
In an imaginary vim syntax file you might have
syntax region italic start='_' end='_' keepend
syntax region bold start='*' end='*' keepend
highlight italic cterm=italic
highlight bold cterm=bold
(yes I know that it's \*
, I left it as *
for clarity.)
The problem here is _strings like *this*_
. Even if your terminal supports italicBold fonts you only get one at a time in vim.
What I really want to do is this:
highlight italic cterm+=italic
highlight bold cterm+=bold
(term
and guiterm
omitted for clarity.)
It's possible to work around this with contained italicBold
and boldItalic
regions that both set cterm=bold,italic
, but things get messy when you want to include underline
and everything gets out of hand entirely when you have a red region and a blue region and you wind up with
syntax region red ... contains=italicRed,boldRed,underlineRed
syntax region italicRed ... contains=italicBoldRed,italicUnderlineRed
syntax region italicBoldRed ... contains=italicBoldUnderlineRed
.
.
.
highlight red ctermfg=red
highlight italicRed cterm=italic ctermfg=red
highlight italicBoldRed cterm=italic,bold ctermfg=red
.
.
.
ad inifinitum.
And the kicker is that really I don't want to hard code the color to red
. I'd prefer to
highlight link red Statement
and then have italicRed
use the same highlight definition as red
but add the italic setting.
There's got to be an easier way to do this. Any suggestions?
No. All syntax plugins that I have seen so far use the workaround you describe.
Why doesn't offer Vim something better? (I had once also wished for the possibility to overlay colors, i.e. when a light yellow background is on top of light gray, it becomes dark yellow.) With high- and low-color terminals and the GUI, this is difficult to implement (anyone like a challenge?), and syntax highlighting is first and foremost for a few common programming constructs (comments, statements, identifiers, etc.), not the elaborate markup you have in mind.