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|.
keepend Don't allow contained matches to go past a
match with the end pattern. See
|:syn-keepend|.
extend Override a "keepend" for an item this region
is contained in. See |:syn-extend|.
excludenl Don't make a pattern with the end-of-line "$"
extend a containing match or item. Only
useful for end patterns. Must be given before
the patterns it applies to. |:syn-excludenl|
start={start-pattern} The search pattern that defines the start of
the region. See |:syn-pattern| below.
skip={skip-pattern} The search pattern that defines text inside
the region where not to look for the end
pattern. See |:syn-pattern| below.
end={end-pattern} The search pattern that defines the end of
the region. See |:syn-pattern| below.
Example: >
:syntax region String start=+"+ skip=+\\"+ end=+"+
<
The start/skip/end patterns and the options can be given in any order.
There can be zero or one skip pattern. There must be one or more
start and end patterns. This means that you can omit the skip
pattern, but you must give at least one start and one end pattern. It
is allowed to have white space before and after the equal sign
(although it mostly looks better without white space).
When more than one start pattern is given, a match with one of these
is sufficient. This means there is an OR relation between the start
patterns. The last one that matches is used. The same is true for
the end patterns.
The search for the end pattern starts right after the start pattern.
Offsets are not used for this. This implies that the match for the
end pattern will never overlap with the start pattern.
The skip and end pattern can match across line breaks, but since the
search for the pattern can start in any line it often does not do what
you want. The skip pattern doesn't avoid a match of an end pattern in
the next line. Use single-line patterns to avoid trouble.
Note: The decision to start a region is only based on a matching start
pattern. There is no check for a matching end pattern. This does NOT
work: >
:syn region First start="(" end=":"
:syn region Second start="(" end=";"
< The Second always matches before the First (last defined pattern has
higher priority). The Second region then continues until the next
';', no matter if there is a ':' before it. Using a match does work: >
:syn match First "(\_.\{-}:"
:syn match Second "(\_.\{-};"
< This pattern matches any character or line break with "\_." and
repeats that with "\{-}" (repeat as few as possible).
*:syn-keepend*
By default, a contained match can obscure a match for the end pattern.
This is useful for nesting. For example, a region that starts with
"{" and ends with "}", can contain another region. An encountered "}"
will then end the contained region, but not the outer region:
{ starts outer "{}" region
{ starts contained "{}" region
} ends contained "{}" region
} ends outer "{} region
If