Home Explore Blog CI



neovim

48th chunk of `runtime/doc/syntax.txt`
ae3362bb37d27086a46a647e2655647e2a9926703a2a96c30000000100000fa1
 also determines where |:syn-keyword| will be checked for a new
	match.

	It is recommended when writing syntax files, to use this command to
	set the correct value for the specific syntax language and not change
	the 'iskeyword' option.

DEFINING KEYWORDS					*:syn-keyword*

:sy[ntax] keyword {group-name} [{options}] {keyword} .. [{options}]

	This defines a number of keywords.

	{group-name}	Is a syntax group name such as "Comment".
	[{options}]	See |:syn-arguments| below.
	{keyword} ..	Is a list of keywords which are part of this group.

	Example: >
  :syntax keyword   Type   int long char
<
	The {options} can be given anywhere in the line.  They will apply to
	all keywords given, also for options that come after a keyword.
	These examples do exactly the same: >
  :syntax keyword   Type   contained int long char
  :syntax keyword   Type   int long contained char
  :syntax keyword   Type   int long char contained
<								*E789* *E890*
	When you have a keyword with an optional tail, like Ex commands in
	Vim, you can put the optional characters inside [], to define all the
	variations at once: >
  :syntax keyword   vimCommand	 ab[breviate] n[ext]
<
	Don't forget that a keyword can only be recognized if all the
	characters are included in the 'iskeyword' option.  If one character
	isn't, the keyword will never be recognized.
	Multi-byte characters can also be used.  These do not have to be in
	'iskeyword'.
	See |:syn-iskeyword| for defining syntax specific iskeyword settings.

	A keyword always has higher priority than a match or region, the
	keyword is used if more than one item matches.	Keywords do not nest
	and a keyword can't contain anything else.

	Note that when you have a keyword that is the same as an option (even
	one that isn't allowed here), you can not use it.  Use a match
	instead.

	The maximum length of a keyword is 80 characters.

	The same keyword can be defined multiple times, when its containment
	differs.  For example, you can define the keyword once not contained
	and use one highlight group, and once contained, and use a different
	highlight group.  Example: >
  :syn keyword vimCommand tag
  :syn keyword vimSetting contained tag
<	When finding "tag" outside of any syntax item, the "vimCommand"
	highlight group is used.  When finding "tag" in a syntax item that
	contains "vimSetting", the "vimSetting" group is used.


DEFINING MATCHES					*:syn-match*

:sy[ntax] match {group-name} [{options}]
		[excludenl]
		[keepend]
		{pattern}
		[{options}]

	This defines one match.

	{group-name}		A syntax group name such as "Comment".
	[{options}]		See |:syn-arguments| below.
	[excludenl]		Don't make a pattern with the end-of-line "$"
				extend a containing match or region.  Must be
				given before the pattern. |:syn-excludenl|
	keepend			Don't allow contained matches to go past a
				match with the end pattern.  See
				|:syn-keepend|.
	{pattern}		The search pattern that defines the match.
				See |:syn-pattern| below.
				Note that the pattern may match more than one
				line, which makes the match depend on where
				Vim starts searching for the pattern.  You
				need to make sure syncing takes care of this.

	Example (match a character constant): >
  :syntax match Character /'.'/hs=s+1,he=e-1
<

DEFINING REGIONS	*:syn-region* *:syn-start* *:syn-skip* *:syn-end*
							*E398* *E399*
:sy[ntax] region {group-name} [{options}]
		[matchgroup={group-name}]
		[keepend]
		[extend]
		[excludenl]
		start={start-pattern} ..
		[skip={skip-pattern}]
		end={end-pattern} ..
		[{options}]

	This defines one region.  It may span several lines.

	{group-name}		A syntax group name such as "Comment".
	[{options}]		See |:syn-arguments| below.
	[matchgroup={group-name}]  The syntax group to use for the following
				start or end pattern matches only.  Not used
				for the text in between the matched start and
				end patterns.  Use NONE to reset to not using
				a different group for the start or end match.
				See |:syn-matchgroup|.

Title: Vim Syntax: Defining Keywords, Matches, and Regions
Summary
This section details how to define keywords, matches, and regions for syntax highlighting in Vim. It explains the syntax and options for the `:syntax keyword`, `:syntax match`, and `:syntax region` commands, including examples and considerations for using these commands effectively. It covers keyword priority, multi-byte characters, the 'iskeyword' option, and the use of start, skip, and end patterns for defining regions spanning multiple lines.