Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only run a highlighting rule as a nextgroup in syntax file?

I have these rules in a custom syntax file.

syn match id '\w\+'
syn keyword _type void int bool string list nextgroup=id

I only want id to be matched after a _type.

like image 839
Kenneth Cheng Avatar asked Mar 25 '23 04:03

Kenneth Cheng


1 Answers

You're already close.

  • To avoid that the id group matches anywhere else, just add contained.
  • For nextgroup=..., the match must begin exactly after the end of the current group. Therefore, you need to include the leading whitespace in the id group match: \s\+, or add skipwhite.
  • The naming convention for syntax groups is to prepend them with your syntax name; I've used my... here.
:syn match myId '\w\+' contained
:syn keyword myType void int bool string list nextgroup=myId skipwhite
like image 200
Ingo Karkat Avatar answered Apr 26 '23 20:04

Ingo Karkat