仅将突出显示规则作为语法文件中的下一个组运行?

Ken*_*eng 4 syntax vim highlight

我在自定义语法文件中有这些规则.

syn match id '\w\+'
syn keyword _type void int bool string list nextgroup=id
Run Code Online (Sandbox Code Playgroud)

我只想id在一个之后匹配_type.

Ing*_*kat 8

你已经很亲了

  • 为了避免id组与其他任何地方匹配,只需添加即可contained.
  • 因为nextgroup=...,匹配必须在当前组结束后完全开始.因此,您需要在id组匹配中包含前导空格:\s\+或添加skipwhite.
  • 语法组的命名约定是在语法名称前加上它们; 我在my...这里用过.
:syn match myId '\w\+' contained
:syn keyword myType void int bool string list nextgroup=myId skipwhite
Run Code Online (Sandbox Code Playgroud)