contains=cfg_DocTag...">

Vim: finding help on creating personalized syntax highlighting

Here is what I got so far:

syntax match cfg_Comment '#.*$' contains=cfg_DocTag
syntax match cfg_DocTag  '#\s*\zs[\\@]\l\+' contained

highlight default link cfg_Comment Comment
highlight default link cfg_DocTag  SpecialComment

Works well for something like:

##
#   @brief The maximum.
#    @type number
# @default 1

Next, I want to highlight the next word after @typeusing a group Type. So I did the following:

syntax match cfg_Comment '#.*$' contains=cfg_DocTag,cfg_DocField_type
syntax match cfg_DocTag  '#\s*\zs[\\@]\l\+' contained

syntax match cfg_DocTag_type   '@type' containedin=cfg_DocTag nextgroup=cfg_DocField_type skipwhite
syntax match cfg_DocField_type '\a\+' contained

highlight default link cfg_Comment       Comment
highlight default link cfg_DocTag        SpecialComment
highlight default link cfg_DocField_type Type

There are 2 problems with this:

  • Now it @typedoesn’t highlight, and I get it, because obviously I didn’t show the group to it, but I expected it to inherit the color from its parent container cfg_DocTag.
  • Of course, now everything in the comments has a color Type, not just the word after @type, and I get it again because I indicated that it cfg_Commentis a container cfg_DocField_type.

I know where the problems arise, but I don’t know how to solve them gracefully and write code as conditional as possible.

, - ,

syntax match cfg_DocTag_type '@type' containedin=cfg_DocTag nextgroup=cfg_DocField_type skipwhite

syntax keyword cfg_DocTag_type @type containedin=cfg_DocTag nextgroup=cfg_DocField_type skipwhite

? , : @type , , . , , , , . :

  • :

    syntax match Test '@type'
    
    highlight default link Test Keyword
    
  • :

    syntax keyword Test @type
    
    highlight default link Test Keyword
    

Update


Ingo . , ?

syntax match cfg_Comment '#.*$' contains=cfg_DocTag
syntax match cfg_DocTag  '#\s*\zs[\\@]\l\+' contained

syntax match cfg_DocTag_type   '@type' transparent containedin=cfg_DocTag nextgroup=cfg_DocField_type skipwhite
syntax match cfg_DocField_type '\a\+' contained

highlight default link cfg_Comment       Comment
highlight default link cfg_DocTag        SpecialComment
highlight default link cfg_DocField_type Type

, . . @ Type , .. . cfg_DocField_type ? ?

+4
1

. cfg_DocTag_type cfg_DocTag , . @ , , nextgroup=cfg_DocField_type , , -, cfg_DocTag ( ) Vim nextgroup.

, , cfg_DocTag_type , cfg_DocTag, . #\s*\zs .

syntax match cfg_Comment '#.*$' contains=cfg_DocTag,cfg_DocTag_type
syntax match cfg_DocTag  '#\s*\zs[\\@]\l\+' contained

syntax match cfg_DocTag_type   '#\s*\zs@type' nextgroup=cfg_DocField_type skipwhite
syntax match cfg_DocField_type '\a\+' contained

highlight default link cfg_Comment       Comment
highlight default link cfg_DocTag        SpecialComment
highlight default link cfg_DocTag_type   cfg_DocTag
highlight default link cfg_DocField_type Type

Re 1: ; @. transparent .

Re "finally": , @ 'iskeyword' ( ), :syn keyword.

Protip: script SyntaxAttr.vim - , .

+1

All Articles