Home Explore Blog CI



neovim

55th chunk of `runtime/doc/syntax.txt`
2c40ed1b7a3597b88b165e68222e6905fea07798a41001150000000100000fa6

This is useful when adding a syntax item afterwards.  An item can be told to
be included inside an already existing item, without changing the definition
of that item.  For example, to highlight a word in a C comment after loading
the C syntax: >
	:syn keyword myword HELP containedin=cComment contained
Note that "contained" is also used, to avoid that the item matches at the top
level.

Matches for "containedin" are added to the other places where the item can
appear.  A "contains" argument may also be added as usual.  Don't forget that
keywords never contain another item, thus adding them to "containedin" won't
work.


nextgroup={group-name},..				*:syn-nextgroup*

The "nextgroup" argument is followed by a list of syntax group names,
separated by commas (just like with "contains", so you can also use patterns).

If the "nextgroup" argument is given, the mentioned syntax groups will be
tried for a match, after the match or region ends.  If none of the groups have
a match, highlighting continues normally.  If there is a match, this group
will be used, even when it is not mentioned in the "contains" field of the
current group.	This is like giving the mentioned group priority over all
other groups.  Example: >
   :syntax match  ccFoobar  "Foo.\{-}Bar"  contains=ccFoo
   :syntax match  ccFoo     "Foo"	    contained nextgroup=ccFiller
   :syntax region ccFiller  start="."  matchgroup=ccBar  end="Bar"  contained

This will highlight "Foo" and "Bar" differently, and only when there is a
"Bar" after "Foo".  In the text line below, "f" shows where ccFoo is used for
highlighting, and "bbb" where ccBar is used. >

   Foo asdfasd Bar asdf Foo asdf Bar asdf
   fff	       bbb	fff	 bbb

Note the use of ".\{-}" to skip as little as possible until the next Bar.
when ".*" would be used, the "asdf" in between "Bar" and "Foo" would be
highlighted according to the "ccFoobar" group, because the ccFooBar match
would include the first "Foo" and the last "Bar" in the line (see |pattern|).


skipwhite						*:syn-skipwhite*
skipnl							*:syn-skipnl*
skipempty						*:syn-skipempty*

These arguments are only used in combination with "nextgroup".	They can be
used to allow the next group to match after skipping some text:
	skipwhite	skip over space and tab characters
	skipnl		skip over the end of a line
	skipempty	skip over empty lines (implies a "skipnl")

When "skipwhite" is present, the white space is only skipped if there is no
next group that matches the white space.

When "skipnl" is present, the match with nextgroup may be found in the next
line.  This only happens when the current item ends at the end of the current
line!  When "skipnl" is not present, the nextgroup will only be found after
the current item in the same line.

When skipping text while looking for a next group, the matches for other
groups are ignored.  Only when no next group matches, other items are tried
for a match again.  This means that matching a next group and skipping white
space and <EOL>s has a higher priority than other items.

Example: >
  :syn match ifstart "\<if.*"	  nextgroup=ifline skipwhite skipempty
  :syn match ifline  "[^ \t].*" nextgroup=ifline skipwhite skipempty contained
  :syn match ifline  "endif"	contained
Note that the "[^ \t].*" match matches all non-white text.  Thus it would also
match "endif".	Therefore the "endif" match is put last, so that it takes
precedence.
Note that this example doesn't work for nested "if"s.  You need to add
"contains" arguments to make that work (omitted for simplicity of the
example).

IMPLICIT CONCEAL					*:syn-conceal-implicit*

:sy[ntax] conceal [on|off]
	This defines if the following ":syntax" commands will define keywords,
	matches or regions with the "conceal" flag set. After ":syn conceal
	on", all subsequent ":syn keyword", ":syn match" or ":syn region"
	defined will have the "conceal" flag set implicitly. ":syn conceal
	off" returns to the normal state where the "conceal" flag must be
	given explicitly.

:sy[ntax] conceal

Title: Vim Syntax Highlighting: More on `nextgroup`, `skipwhite`, `skipnl`, `skipempty`, and Implicit Conceal
Summary
This section expands on the `nextgroup` argument, explaining how it gives certain groups priority in matching after the current match or region ends. It introduces `skipwhite`, `skipnl`, and `skipempty` arguments for `nextgroup` that allow skipping whitespace, newlines, and empty lines, respectively, before searching for the next group. It describes how these skip options affect matching priority. Also it explains the usage of `:syntax conceal [on|off]` to define if the following syntax commands will define keywords, matches or regions with the "conceal" flag set.