开发者

How to have in Vim one syntax highlighting and two colors with two different start/end sets?

Let us say I have a file : memovi.txt (to learn vi...) in which each line has the same structure (command colon explanation) ; for example :

dw : Deletes from the current cursor location to the next word

(NB : text white, background black)

Now, I want to do 2 things :

1) highlight the command in green I did it by defining a region with start and end, which I did with start=≈, and end=≈

So, in my .vimrc I have :

:command Tran :source syntax.vim

and in my syntax.vim, I have :

syn region cTran conceal start='≈' end='≈'
hi cTran ctermbg=Black ctermfg=DarkGreen

2) but I wish, of course, to insert an example (eg, d4w), and highlight it in a different color (magenta), and I would like to highlight it by putting it between start=• and end=• to bring a result such as :

≈dw≈ (thus in green) : Deletes from the current cursor location to the next word. •d4w• (thus in magenta) : delete 4 words

开发者_如何学JAVA

But it seems I cannot define one syntax highlighting with two different "coloring" depending on two different start/end sets. Or can I ?

Thanks in advance


The vim help file syntax (help.vim) is a good template for this behaviour. It uses the bar "|" to delimit help hyperlinks. The bar is then concealed.

Here is the syntax.vim which should achieve what you want for the ASCII delimiters | and =. I haven't tested it with your Unicode characters, but I can't see why anything should change (although I am unschooled in the vagaries of Unicode).

syn match cTransA "|.*|" contains=delimA
syn match cTransB "=.*=" contains=delimB
syn match delimA contained '|' conceal
syn match delimB contained '=' conceal
hi cTransA ctermfg=DarkGreen
hi cTransB ctermfg=Magenta

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜