0

I think it is possible but can not figure how one can highlight only the first match of contained syntax?

syn clear
syntax cluster TitleParts contains=TitleNum,TitleType,TitleRest
syntax match MyTitle /\v^\s+\d+\)\s+.*$/ contains=@TitleParts
syntax match TitleNum /\v\s+\d+\)\s*/ contained nextgroup=TitleType
syntax match TitleType /\v(this|that)/ contained
syntax match TitleRest /\v\(.+\)/ contained
hi link MyTitle Title
hi link TitleNum Statement
hi link TitleType Type
hi link TitleRest Comment

  1) this Hello World this (Bla bla bla 1 2 3 4 5)

enter image description here

0

Well, I've found the answer while experimenting... not sure if this is the best one :)

syn clear
syntax cluster TitleParts contains=TitleFront,TitleTail
syntax match TitleFront /\v^\s+\d+\)\s((this|that)\s)?/ contains=TitleNum,TitleType containedin=@TitleParts
syntax match MyTitle /\v^\s+\d+\)\s+.*$/ contains=@TitleParts
syntax match TitleNum /\v\s+\d+\)\s*/ contained containedin=TitleFront
syntax match TitleType /\v(this|that)/ contained containedin=TitleFront
syntax match TitleTail /\v\(\d+\)\s\(.{-}\)$/ contained containedin=MyTitle
hi link MyTitle Title
hi link TitleNum Statement
hi link TitleType Type
hi link TitleTail Comment

  123) this Hello World this (1) (Bla bla bla 1 2 3 4 5)

  1) that Hello World this (22) (Bla bla bla 1 2 3 4 5)

enter image description here

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.