はcontains=...
とcontained
キーワードを使用して、それを行うための一つの方法である:もちろん
" Add some highlight defs:
hi link MyLeftPart SpecialKey
hi link MyMinus Operator
hi link MyRightPart String
" Match the whole lines, and make the given highlight work only
" with lines with this format: "x - blah blah..." :
syn match MyLeftPart /^. - .*/ contains=MyMinus
" Leave the very first char highlighted with MyLeftPart, and
" highlight the rest with MyMinus:
syn match MyMinus /.\zs.*/ contains=MyRightPart contained
" Leave the minus highlighted with MyMinus, and highlight the rest
" with MyRightPart:
syn match MyRightPart/- \zs.*/ contained
方が良い(例えば、\s\+-\s\+
によって-
を交換することにより、ニーズに合わせて3つの与えられたパターンを修正することができ、ハイライトを右にシフトしたラインでもハイライトを動作させるためには^
を削除してください)。
:syn match
の代わりにmatchadd()
関数を使用するなど、別のソリューションを使用することもできます。
"repectively"とはどういう意味ですか?文字で始まり、マイナス記号で始まるすべての行にマッチしたいですか?または、マイナス記号の前と後ろを区別してハイライトしたいのですか? – yolenoyer
@yolenoyer私は3つのセクションを強調したい:マイナス記号、その前と後ろ。私は現在マイナス記号を強調するだけで成功しています。 – Jimmy