Folks, I'm writing a syntax highlighting script for vim, but I'm struggling on how to highlight only a submatch of a pattern.
For example, suppose that I want to highlight any number within #
, like #42#
to highlight only the 42 and not the #
.
I don't fully understand what the \@= operator does, but I'm trying to use it like so:
syn match Number "\(#\)\@=\d\+\(#\)\@="
Edit: Just complementing Kent's answer, from the man page:
*/\zs*
\zs Matches at any position, and sets the start of the match there: The
next char is the first char of the whole match. |/zero-width|
Example: >
/^\s*\zsif
< matches an "if" at the start of a line, ignoring white space.
Can be used multiple times, the last one encountered in a matching
branch is used. Example: >
/\(.\{-}\zsFab\)\{3}
< Finds the third occurrence of "Fab".
{not in Vi} {not available when compiled without the |+syntax| feature}
*/\ze*
\ze Matches at any position, and sets the end of the match there: The
previous char is the last char of the whole match. |/zero-width|
Can be used multiple times, the last one encountered in a matching
branch is used.
Example: "end\ze\(if\|for\)" matches the "end" in "endif" and
"endfor".
{not in Vi} {not available when compiled without the |+syntax| feature}