Home Explore Blog CI



neovim

18th chunk of `runtime/doc/pattern.txt`
30614768213ea04bb11df9580b5662c471fb8d1affaecb960000000100000fa2
 matches as much of the list of atoms it contains as possible.  Thus
	it stops at the first atom that doesn't match.  For example: >
		/r\%[ead]
<	matches "r", "re", "rea" or "read".  The longest that matches is used.
	To match the Ex command "function", where "fu" is required and
	"nction" is optional, this would work: >
		/\<fu\%[nction]\>
<	The end-of-word atom "\>" is used to avoid matching "fu" in "full".
	It gets more complicated when the atoms are not ordinary characters.
	You don't often have to use it, but it is possible.  Example: >
		/\<r\%[[eo]ad]\>
<	Matches the words "r", "re", "ro", "rea", "roa", "read" and "road".
	There can be no \(\), \%(\) or \z(\) items inside the [] and \%[] does
	not nest.
	To include a "[" use "[[]" and for "]" use []]", e.g.,: >
		/index\%[[[]0[]]]
<	matches "index" "index[", "index[0" and "index[0]".

				*/\%d* */\%x* */\%o* */\%u* */\%U* *E678*

\%d123	Matches the character specified with a decimal number.  Must be
	followed by a non-digit.
\%o40	Matches the character specified with an octal number up to 0o377.
	Numbers below 0o40 must be followed by a non-octal digit or a
	non-digit.
\%x2a	Matches the character specified with up to two hexadecimal characters.
\%u20AC	Matches the character specified with up to four hexadecimal
	characters.
\%U1234abcd	Matches the character specified with up to eight hexadecimal
	characters, up to 0x7fffffff (the maximum allowed value is INT_MAX
	|E1541|, but the maximum valid Unicode codepoint is U+10FFFF).

==============================================================================
7. Ignoring case in a pattern					*/ignorecase*

If the 'ignorecase' option is on, the case of normal letters is ignored.
'smartcase' can be set to ignore case when the pattern contains lowercase
letters only.
							*/\c* */\C*
When "\c" appears anywhere in the pattern, the whole pattern is handled like
'ignorecase' is on.  The actual value of 'ignorecase' and 'smartcase' is
ignored.  "\C" does the opposite: Force matching case for the whole pattern.
Note that 'ignorecase', "\c" and "\C" are not used for the character classes.

Examples:
      pattern	'ignorecase'  'smartcase'	matches ~
	foo	  off		-		foo
	foo	  on		-		foo Foo FOO
	Foo	  on		off		foo Foo FOO
	Foo	  on		on		    Foo
	\cfoo	  -		-		foo Foo FOO
	foo\C	  -		-		foo

Technical detail:				*NL-used-for-Nul*
<Nul> characters in the file are stored as <NL> in memory.  In the display
they are shown as "^@".  The translation is done when reading and writing
files.  To match a <Nul> with a search pattern you can just enter CTRL-@ or
"CTRL-V 000".  This is probably just what you expect.  Internally the
character is replaced with a <NL> in the search pattern.  What is unusual is
that typing CTRL-V CTRL-J also inserts a <NL>, thus also searches for a <Nul>
in the file.

						*CR-used-for-NL*
When 'fileformat' is "mac", <NL> characters in the file are stored as <CR>
characters internally.  In the text they are shown as "^J".  Otherwise this
works similar to the usage of <NL> for a <Nul>.

When working with expression evaluation, a <NL> character in the pattern
matches a <NL> in the string.  The use of "\n" (backslash n) to match a <NL>
doesn't work there, it only works to match text in the buffer.

				*pattern-multi-byte* *pattern-multibyte*
Patterns will also work with multibyte characters, mostly as you would
expect.  But invalid bytes may cause trouble, a pattern with an invalid byte
will probably never match.

==============================================================================
8. Composing characters					*patterns-composing*

							*/\Z*
When "\Z" appears anywhere in the pattern, all composing characters are
ignored.  Thus only the base characters need to match, the composing
characters may be different and the number of composing characters may differ.
Exception: If the pattern starts with one or more composing characters, these
must match.
							*/\%C*
Use "\%C" to skip any composing characters.  For

Title: Vim Regex: Optional Matching, Character Codes, Case Ignoring, Multibyte Characters and Composing Characters
Summary
This section covers optional atom matching in Vim regex using \%[], including examples. It explains how to specify characters by their decimal, octal, hexadecimal, or Unicode values using \%d, \%o, \%x, \%u, and \%U. The section then addresses case sensitivity, introducing \c and \C to globally ignore or enforce case matching, overriding 'ignorecase' and 'smartcase'. Also, explains how \Z ignores composing characters and how to skip composing characters with \%C.