سؤال

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
هل كانت مفيدة؟

المحلول

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,_"

نصائح أخرى

The best solution seems to be not using the keyword option, but using the matches option instead.

syn match pddlLabel ':[a-zA-Z0-9]\+'
hi def link pddlLabel Statement
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top