Home Explore Blog CI



neovim

12th chunk of `runtime/doc/pattern.txt`
45c13a6b44e4767de352e11f77129efc5b841de9d25c32970000000100000fa5
	matches end-of-line <EOL>; at other positions, matches literal '$'.
	|/zero-width|

							*/\$*
\$	Matches literal '$'.  Can be used at any position in the pattern, but
	not inside [].

							*/\_$*
\_$	Matches end-of-line. |/zero-width|  Can be used at any position in the
	pattern, but not inside [].  Note that "a\_$b" never matches, since
	"b" cannot match an end-of-line.  Use "a\nb" instead |/\n|.
	Example		matches ~
	foo\_$\_s*	"foo" at end-of-line and following white space and
			blank lines

.	(with 'nomagic': \.)				*/.* */\.*
	Matches any single character, but not an end-of-line.

							*/\_.*
\_.	Matches any single character or end-of-line.
	Careful: "\_.*" matches all text to the end of the buffer!

							*/\<*
\<	Matches the beginning of a word: The next char is the first char of a
	word.  The 'iskeyword' option specifies what is a word character.
	|/zero-width|

							*/\>*
\>	Matches the end of a word: The previous char is the last char of a
	word.  The 'iskeyword' option specifies what is a word character.
	|/zero-width|

							*/\zs*
\zs	Matches at any position, but not inside [], 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".
	This cannot be followed by a multi. *E888*

							*/\ze*
\ze	Matches at any position, but not inside [], 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".
	This cannot be followed by a multi. |E888|

						*/\%^* *start-of-file*
\%^	Matches start of the file.  When matching with a string, matches the
	start of the string.
	For example, to find the first "VIM" in a file: >
		/\%^\_.\{-}\zsVIM
<
						*/\%$* *end-of-file*
\%$	Matches end of the file.  When matching with a string, matches the
	end of the string.
	Note that this does NOT find the last "VIM" in a file: >
		/VIM\_.\{-}\%$
<	It will find the next VIM, because the part after it will always
	match.  This one will find the last "VIM" in the file: >
		/VIM\ze\(\(VIM\)\@!\_.\)*\%$
<	This uses |/\@!| to ascertain that "VIM" does NOT match in any
	position after the first "VIM".
	Searching from the end of the file backwards is easier!

						*/\%V*
\%V	Match inside the Visual area.  When Visual mode has already been
	stopped match in the area that |gv| would reselect.
	This is a |/zero-width| match.  To make sure the whole pattern is
	inside the Visual area put it at the start and just before the end of
	the pattern, e.g.: >
		/\%Vfoo.*ba\%Vr
<	This also works if only "foo bar" was Visually selected.  This: >
		/\%Vfoo.*bar\%V
<	would match "foo bar" if the Visual selection continues after the "r".
	Only works for the current buffer.

						*/\%#* *cursor-position*
\%#	Matches with the cursor position.  Only works when matching in a
	buffer displayed in a window.
	WARNING: When the cursor is moved after the pattern was used, the
	result becomes invalid.  Vim doesn't automatically update the matches.
	This is especially relevant for syntax highlighting and 'hlsearch'.
	In other words: When the cursor moves the display isn't updated for
	this change.  An update is done for lines which are changed (the whole
	line is updated) or when using the |CTRL-L| command (the whole screen
	is updated).  Example, to highlight the word under the cursor: >
		/\k*\%#\k*
<	When 'hlsearch' is set and you move the cursor around and make changes
	this will clearly show when the match is updated or not.

						*/\%'m* */\%<'m* */\%>'m*
\%'m	Matches with the position of mark m.
\%<'m	Matches before the position of mark m.
\%>'m	Matches after

Title: Vim Regex: Zero-Width Matches \zs, \ze, %^, %$, %V, %# , and Marks
Summary
This section describes more zero-width matching items in Vim regular expressions. It covers \zs and \ze for setting the start and end of a match, %^ and %$ for matching the start and end of a file (or string), %V for matching inside the Visual area, %# for matching the cursor position, and %'m, %<'m, and %>'m for matching at, before, and after the position of a mark, respectively.