Search code examples
vimvim-syntax-highlighting

Highlighting keywords beginning with colon in Vim


I wrote a vim syntax file. I notice that all keywords except those beginning with a colon (:) are being highlighted. Is there any way to escape colons in Vim?

Here's a section of the file:

syn keyword actionLabel :action nextgroup=actionName skipwhite
syn keyword problemLabels :goal :init :domain
syn keyword advLabels :types
syn keyword pondLabels :observe


hi def link actionLabel     Statement
hi def link problemLabels   Statement
hi def link advLabels       Statement
hi def link pondLabels      Statement

Solution

  • From :h :syn-define about keywords...

    It can only contain keyword characters, according to the 'iskeyword' option. It cannot contain other syntax items. It will only match with a complete word (there are no keyword characters before or after the match). The keyword "if" would match in "if(a=b)", but not in "ifdef x", because "(" is not a keyword character and "d" is.

    That means you'll have to modify iskeyword for your file type to include the colon character (ascii 58). Starting from the vi default, we can support any alphabetic character, number, underscore, or colon:

    set iskeyword="@,48-58,_"