Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
{pattern}
and go {offset} lines up or down.
linewise./<CR>
/<CR> Search forward for the [count]'th occurrence of the
latest used pattern last-pattern with latest used
{offset}.{offset}
is empty no offset is used.{pattern}
and go {offset} lines up or
down linewise.?<CR>
?<CR> Search backward for the [count]'th occurrence of the
latest used pattern last-pattern with latest used
{offset}.{offset}
is empty no offset is used.n
n Repeat the latest "/" or "?" [count] times.
If the cursor doesn't move the search is repeated with
count + 1.
last-patternN
N Repeat the latest "/" or "?" [count] times in
opposite direction. last-patternstar
E348
E349
* Search forward for the [count]'th occurrence of the
word nearest to the cursor. The word used for the
search is the first of:
1. the keyword under the cursor 'iskeyword'
2. the first keyword after the cursor, in the
current line
3. the non-blank word under the cursor
4. the first non-blank word after the cursor,
in the current line
Only whole keywords are searched for, like with the
command "/\<keyword\>". exclusive
'ignorecase' is used, 'smartcase' is not.
v_star-default
{Visual}
* In Visual mode, search forward for the current selection.
default-mappings#
# Same as "*", but search backward. The pound sign
(character 163) also works. If the "#" key works as
backspace, try using "stty erase <BS>
" before starting
Vim (<BS>
is CTRL-H
or a real backspace).
v_#-default
{Visual}
# In Visual mode, search backward for the current selection.
default-mappingsgstar
g* Like "*", but don't put "\<" and "\>" around the word.
This makes the search also find matches that are not a
whole word.g#
g# Like "#", but don't put "\<" and "\>" around the word.
This makes the search also find matches that are not a
whole word.gd
gd Goto local Declaration. When the cursor is on a local
variable, this command will jump to its declaration.
This was made to work for C code, in other languages
it may not work well.
First Vim searches for the start of the current
function, just like "[[". If it is not found the
search stops in line 1. If it is found, Vim goes back
until a blank line is found. From this position Vim
searches for the keyword under the cursor, like with
"*", but lines that look like a comment are ignored
(see 'comments' option).
Note that this is not guaranteed to work, Vim does not
really check the syntax, it only searches for a match
with the keyword. If included files also need to be
searched use the commands listed in include-search.
After this command n searches forward for the next
match (not backward).gD
gD Goto global Declaration. When the cursor is on a
global variable that is defined in the file, this
command will jump to its declaration. This works just
like "gd", except that the search for the keyword
always starts in line 1.1gd
1gd Like "gd", but ignore matches inside a {} block that
ends before the cursor position.1gD
1gD Like "gD", but ignore matches inside a {} block that
ends before the cursor position.CTRL-C
CTRL-C Interrupt current (search) command.
In Normal mode, any pending command is aborted.:noh
:nohlsearch
:noh[lsearch] Stop the highlighting for the 'hlsearch' option. It
is automatically turned back on when using a search
command, or setting the 'hlsearch' option.
This command doesn't work in an autocommand, because
the highlighting state is saved and restored when
executing autocommands autocmd-searchpat.
Same thing for when invoking a user function.<CR>
to actually position the cursor at the displayed match. Or
use <Esc>
to abandon the search.nohlsearch-auto
All matches for the last used search pattern will be highlighted if you set
the 'hlsearch' option. This can be suspended with the :nohlsearch command
or auto suspended with nohlsearch plugin. See nohlsearch-install.[1/5] Cursor is on first of 5 matches. [1/>99] Cursor is on first of more than 99 matches. [>99/>99] Cursor is after 99 match of more than 99 matches. [?/??] Unknown how many matches exists, generating the statistics was aborted because of search timeout.Note: the count does not take offset into account.
E486
Pattern not found
Note that for the :global
command, you get a normal message "Pattern not
found", for Vi compatibility.
For the :s command the "e" flag can be used to avoid the error message
:s_flags.search-offset
{offset}
These commands search for the specified pattern. With "/" and "?" an
additional offset may be given. There are two types of offsets: line offsets
and character offsets./foo<CR> find "foo" c//e<CR> change until end of match bar<Esc> type replacement //<CR> go to start of next match c//e<CR> change until end of match beep<Esc> type another replacement etc.
//;
E386
A very special offset is ';' followed by another search command. For example:/test 1/;/test /test.*/+1;?ing?The first one first finds the next occurrence of "test 1", and then the first occurrence of "test" after that.
last-pattern
The last used pattern and offset are remembered. They can be used to repeat
the search, possibly in another direction or with another count. Note that
two patterns are remembered: One for "normal" search commands and one for the
substitute command ":s". Each time an empty pattern is given, the previously
used pattern is used. However, if there is no previous search command, a
previous substitute pattern is used, if possible.:let @/ = ""This will not set the pattern to an empty string, because that would match everywhere. The pattern is really cleared, like when starting Vim.
search-range
You can limit the search command "/" to a certain range of lines by including
\%>l items. For example, to match the word "limit" below line 199 and above
line 300:/\%>199l\%<300llimitAlso see /\%>l.
:.,300s/Pattern//gcThis command will search from the cursor position until line 300 for "Pattern". At the match, you will be asked to type a character. Type 'q' to stop at this match, type 'n' to find the next match.
<Tab>
s and/or <Space>
s).
Note that if you type with ten fingers, the characters are easy to remember:
the "#" is under your left hand middle finger (search to the left and up) and
the "*" is under your right hand middle finger (search to the right and down).
(this depends on your keyboard layout though).
E956
In very rare cases a regular expression is used recursively. This can happen
when executing a pattern takes a long time and when checking for messages on
channels a callback is invoked that also uses a pattern or an autocommand is
triggered. In most cases this should be fine, but if a pattern is in use when
it's used again it fails. Usually this means there is something wrong with
the pattern./bar
/\bar
/pattern
1. A pattern is one or more branches, separated by "\|". It matches anything
that matches one of the branches. Example: "foo\|beep" matches "foo" and
matches "beep". If more than one branch matches, the first one is used./branch
/\&
2. A branch is one or more concats, separated by "\&". It matches the last
concat, but only if all the preceding concats also match at the same
position. Examples:
"foobeep\&..." matches "foo" in "foobeep".
".*Peter\&.*Bob" matches in a line containing both "Peter" and "Bob"/concat
3. A concat is one or more pieces, concatenated. It matches a match for the
first piece, followed by a match for the second piece, etc. Example:
"f[0-9]b", first matches "f", then a digit and then "b"./piece
4. A piece is an atom, possibly followed by a multi, an indication of how many
times the atom can be matched. Example: "a*" matches any sequence of "a"
characters: "", "a", "aa", etc. See /multi./atom
5. An atom can be one of a long list of items. Many atoms match one character
in the text. It is often an ordinary character or a character class.
Parentheses can be used to make a pattern into an atom. The "\z(\)"
construct is only for syntax highlighting./\%#=
two-engines
NFA
Vim includes two regexp engines:
1. An old, backtracking engine that supports everything.
2. A new, NFA engine that works much faster on some patterns, possibly slower
on some patterns.
E1281
Vim will automatically select the right engine for you. However, if you run
into a problem or want to specifically select one engine or the other, you can
prepend one of the following to the pattern:E864
E868
E874
E875
E876
E877
E878
If selecting the NFA engine and it runs into something that is not implemented
the pattern will not match. This is only useful when debugging Vim./\m
/\M
Use of "\m" makes the pattern after it be interpreted as if 'magic' is set,
ignoring the actual value of the 'magic' option.
Use of "\M" makes the pattern after it be interpreted as if 'nomagic' is used.
/\v
/\V
Use of "\v" means that after it, all ASCII characters except '0'-'9', 'a'-'z',
'A'-'Z' and '_' have special meaning: "very magic"/multi
E61
E62
More explanation and examples below, follow the links. E64
E871
E59
/\@> \@> \@> 1, like matching a whole pattern
/\@= \@= \@= nothing, requires a match /zero-width
/\@! \@! \@! nothing, requires NO match /zero-width
/\@<= \@<= \@<= nothing, requires a match behind /zero-width
/\@<! \@<! \@<! nothing, requires NO match behind /zero-width/ordinary-atom
More explanation and examples below, follow the links.E71
/\%$ \%$ \%$ end of file /zero-width
/\%V \%V \%V inside Visual area /zero-width
/\%# \%# \%# cursor position /zero-width
/\%'m \%'m \%'m mark m position /zero-width
/\%l \%23l \%23l in line 23 /zero-width
/\%c \%23c \%23c in column 23 /zero-width
/\%v \%23v \%23v in virtual column 23 /zero-width/character-classes
<Space>
and <Tab>
/\S \S \S non-whitespace character; opposite of \s
/\d \d \d digit: [0-9]
/\D \D \D non-digit: [^0-9]
/\x \x \x hex digit: [0-9A-Fa-f]
/\X \X \X non-hex digit: [^0-9A-Fa-f]
/\o \o \o octal digit: [0-7]
/\O \O \O non-octal digit: [^0-7]
/\w \w \w word character: [0-9A-Za-z_]
/\W \W \W non-word character: [^0-9A-Za-z_]
/\h \h \h head of word character: [A-Za-z_]
/\H \H \H non-head of word character: [^A-Za-z_]
/\a \a \a alphabetic character: [A-Za-z]
/\A \A \A non-alphabetic character: [^A-Za-z]
/\l \l \l lowercase character: [a-z]
/\L \L \L non-lowercase character: [^a-z]
/\u \u \u uppercase character: [A-Z]
/\U \U \U non-uppercase character [^A-Z]
/\_ \_x \_x where x is any of the characters above: character
class with end-of-line included
(end of character classes)<Esc>
/\t \t \t <Tab>
/\r \r \r <CR>
/\b \b \b <BS>
/\n \n \n end-of-line
/~ ~ \~ last given substitute string
/\1 \1 \1 same string as matched by first \(\)
/\2 \2 \2 Like "\1", but uses second \(\)
...
/\9 \9 \9 Like "\1", but uses ninth \(\)
E68
/\z1 \z1 \z1 only for syntax highlighting, see :syn-ext-match
...
/\z1 \z9 \z9 only for syntax highlighting, see :syn-ext-match<EOL>
or a space./star
/\star
* (use \* when 'magic' is not set)
Matches 0 or more of the preceding atom, as many as possible.
/\+
\+ Matches 1 or more of the preceding atom, as many as possible.
/\=
\= Matches 0 or 1 of the preceding atom, as many as possible.
/\?
\? Just like \=. Cannot be used when searching backwards with the "?"
command./\{
E60
E554
E870
\{n,m} Matches n to m of the preceding atom, as many as possible
\{n} Matches n of the preceding atom
\{n,} Matches at least n of the preceding atom, as many as possible
\{,m} Matches 0 to m of the preceding atom, as many as possible
\{} Matches 0 or more of the preceding atom, as many as possible (like "*")
/\{-
\{-n,m} matches n to m of the preceding atom, as few as possible
\{-n} matches n of the preceding atom
\{-n,} matches at least n of the preceding atom, as few as possible
\{-,m} matches 0 to m of the preceding atom, as few as possible
\{-} matches 0 or more of the preceding atom, as few as possiblenon-greedy
If a "-" appears immediately after the "{", then a shortest match
first algorithm is used (see example below). In particular, "\{-}" is
the same as "*" but uses the shortest match first algorithm. BUT: A
match that starts earlier is preferred over a shorter match: "a\{-}b"
matches "aaab" in "xaaab"./\@=
\@= Matches the preceding atom with zero width.
Like "(?=pattern)" in Perl.
/zero-width
When using "\@=" (or "^", "$", "\<", "\>") no characters are included
in the match. These items are only used to check if a match can be
made. This can be tricky, because a match with following items will
be done in the same position. The last example above will not match
"foobarfoo", because it tries match "foo" in the same position where
"bar" matched./\@!
\@! Matches with zero width if the preceding atom does NOT match at the
current position. /zero-width
Like "(?!pattern)" in Perl.
/^\%(.*bar\)\@!.*\zsfoo
/\@<=
\@<= Matches with zero width if the preceding atom matches just before what
follows. /zero-width
Like "(?<=pattern)" in Perl, but Vim allows non-fixed-width patterns.
/\@<!
\@<! Matches with zero width if the preceding atom does NOT match just
before what follows. Thus this matches if there is no position in the
current or previous line where the atom matches such that it ends just
before what follows. /zero-width
Like "(?<!pattern)" in Perl, but Vim allows non-fixed-width patterns.
The match with the preceding atom is made to end just before the match
with what follows, thus an atom that ends in ".*" will work.
Warning: This can be slow (because many positions need to be checked
for a match). Use a limit if you can, see below.
/\@>
\@> Matches the preceding atom like matching a whole pattern.
Like "(?>pattern)" in Perl.
/^
^ At beginning of pattern or after "\|", "\(", "\%(" or "\n": matches
start-of-line; at other positions, matches literal '^'. /zero-width
/\^
\^ Matches literal '^'. Can be used at any position in the pattern, but
not inside []./\_^
\_^ Matches start-of-line. /zero-width Can be used at any position in
the pattern, but not inside [].
/$
$ At end of pattern or in front of "\|", "\)" or "\n" ('magic' on):
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.
/\_.
\_. 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
/\(.\{-}\zsFab\)\{3}
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\_.\{-}\%$
/VIM\ze\(\(VIM\)\@!\_.\)*\%$
/\%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
/\%Vfoo.*bar\%V
/\%#
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*
/\%'m
/\%<'m
/\%>'m
\%'m Matches with the position of mark m.
\%<'m Matches before the position of mark m.
\%>'m Matches after the position of mark m.
Example, to highlight the text from mark 's to 'e:/.\%>'s.*\%<'e..
/\%l
/\%>l
/\%<l
E951
E1204
\%23l Matches in a specific line.
\%<23l Matches above a specific line (lower line number).
\%>23l Matches below a specific line (higher line number).
\%.l Matches at the cursor line.
\%<.l Matches above the cursor line.
\%>.l Matches below the cursor line.
These six can be used to match specific lines in a buffer. The "23"
can be any line number. The first line is 1.
WARNING: When inserting or deleting lines Vim does not automatically
update the matches. This means Syntax highlighting quickly becomes
wrong. Also when referring to the cursor position (".") and
the cursor moves the display isn't updated for this change. An update
is done when using the CTRL-L command (the whole screen is updated).
Example, to highlight the line where the cursor currently is::exe '/\%' .. line(".") .. 'l'
/\%.l
/\%c
/\%>c
/\%<c
\%23c Matches in a specific column.
\%<23c Matches before a specific column.
\%>23c Matches after a specific column.
\%.c Matches at the cursor column.
\%<.c Matches before the cursor column.
\%>.c Matches after the cursor column.
These six can be used to match specific columns in a buffer or string.
The "23" can be any column number. The first column is 1. Actually,
the column is the byte number (thus it's not exactly right for
multibyte characters).
WARNING: When inserting or deleting text Vim does not automatically
update the matches. This means Syntax highlighting quickly becomes
wrong. Also when referring to the cursor position (".") and
the cursor moves the display isn't updated for this change. An update
is done when using the CTRL-L command (the whole screen is updated).
Example, to highlight the column where the cursor currently is::exe '/\%' .. col(".") .. 'c'
/\%.c
/\%>43c.\%<46c
/\%v
/\%>v
/\%<v
\%23v Matches in a specific virtual column.
\%<23v Matches before a specific virtual column.
\%>23v Matches after a specific virtual column.
\%.v Matches at the current virtual column.
\%<.v Matches before the current virtual column.
\%>.v Matches after the current virtual column.
These six can be used to match specific virtual columns in a buffer or
string. When not matching with a buffer in a window, the option
values of the current window are used (e.g., 'tabstop').
The "23" can be any column number. The first column is 1.
Note that some virtual column positions will never match, because they
are halfway through a tab or other character that occupies more than
one screen character.
WARNING: When inserting or deleting text Vim does not automatically
update highlighted matches. This means Syntax highlighting quickly
becomes wrong. Also when referring to the cursor position (".") and
the cursor moves the display isn't updated for this change. An update
is done when using the CTRL-L command (the whole screen is updated).
Example, to highlight all the characters after virtual column 72:/\%>72v.*
/^.*\%17v
/\%>.v.*
/^.*\%17v.
/^.*\%<18v.
/.*\%17v
/\i
\I like "\i", but excluding digits /\I
\k keyword character (see 'iskeyword' option) /\k
\K like "\k", but excluding digits /\K
\f file name character (see 'isfname' option) /\f
\F like "\f", but excluding digits /\F
\p printable character (see 'isprint' option) /\p
\P like "\p", but excluding digits /\P
whitespace
white-space
\s whitespace character: <Space>
and <Tab>
/\s
\S non-whitespace character; opposite of \s /\S
\d digit: [0-9] /\d
\D non-digit: [^0-9] /\D
\x hex digit: [0-9A-Fa-f] /\x
\X non-hex digit: [^0-9A-Fa-f] /\X
\o octal digit: [0-7] /\o
\O non-octal digit: [^0-7] /\O
\w word character: [0-9A-Za-z_] /\w
\W non-word character: [^0-9A-Za-z_] /\W
\h head of word character: [A-Za-z_] /\h
\H non-head of word character: [^A-Za-z_] /\H
\a alphabetic character: [A-Za-z] /\a
\A non-alphabetic character: [^A-Za-z] /\A
\l lowercase character: [a-z] /\l
\L non-lowercase character: [^a-z] /\L
\u uppercase character: [A-Z] /\u
\U non-uppercase character: [^A-Z] /\U
/\_
E63
/\_i
/\_I
/\_k
/\_K
/\_f
/\_F
/\_p
/\_P
/\_s
/\_S
/\_d
/\_D
/\_x
/\_X
/\_o
/\_O
/\_w
/\_W
/\_h
/\_H
/\_a
/\_A
/\_l
/\_L
/\_u
/\_U
\_x Where "x" is any of the characters above: The character class with
end-of-line added
(end of character classes)<Esc>
/\e
\t matches <Tab>
/\t
\r matches <CR>
/\r
\b matches <BS>
/\b
\n matches an end-of-line /\n
When matching in a string instead of buffer text a literal newline
character is matched./\(
/\(\)
/\)
E.g., "\(^a\)" matches 'a' at the start of a line.
There can only be nine of these. You can use "\%(" to add more, but
not counting it as a sub-expression.
E51
E54
E55
E872
E873
/\1
E65
the first sub-expression in \( and \).
Example: "\([a-z]\).\1" matches "ata", "ehe", "tot", etc.
\2 Like "\1", but uses second sub-expression, /\2
... /\3
\9 Like "\1", but uses ninth sub-expression. /\9
Note: The numbering of groups is done based on which "\(" comes first
in the pattern (going left to right), NOT based on what is matched
first./\%(\)
/\%(
E53
Just like \(\), but without counting it as a sub-expression. This
allows using more groups and it's a little bit faster./\
/\\
\x A backslash followed by a single character, with no special meaning,
is reserved for future expansions/[]
/\[]
/\_[]
/collection
E76
\_[]
A collection. This is a sequence of characters enclosed in square
brackets. It matches any single character in the collection.
/[\n]
With "\_" prepended the collection also includes the end-of-line.
The same can be done by including "\n" in the collection. The
end-of-line is also matched when the collection starts with "^"! Thus
"\_[^ab]" matches the end-of-line and any character but "a" and "b".
This makes it Vi compatible: Without the "\_" or "\n" the collection
does not match an end-of-line.
E769
When the ']' is not there Vim will not give an error message but
assume no collection is used. Useful to search for '['. However, you
do get E769 for internal searching. And be aware that in a
:substitute
command the whole command becomes the pattern. E.g.
":s/[/x/" searches for "[/x" and replaces it with nothing. It does
not search for "[" and replaces it with "x"!E944
E945
If the sequence begins with "^", it matches any single character NOT
in the collection: "[^xyz]" matches anything but 'x', 'y' and 'z'.
[:alnum:]
[:alnum:] isalnum ASCII letters and digits
[:alpha:]
[:alpha:] isalpha ASCII letters
[:blank:]
[:blank:] space and tab
[:cntrl:]
[:cntrl:] iscntrl ASCII control characters
[:digit:]
[:digit:] decimal digits '0' to '9'
[:graph:]
[:graph:] isgraph ASCII printable characters excluding
space
[:lower:]
[:lower:] (1) lowercase letters (all letters when
'ignorecase' is used)
[:print:]
[:print:] (2) printable characters including space
[:punct:]
[:punct:] ispunct ASCII punctuation characters
[:space:]
[:space:] whitespace characters: space, tab, CR,
NL, vertical tab, form feed
[:upper:]
[:upper:] (3) uppercase letters (all letters when
'ignorecase' is used)
[:xdigit:]
[:xdigit:] hexadecimal digits: 0-9, a-f, A-F
[:return:]
[:return:] the <CR>
character
[:tab:]
[:tab:] the <Tab>
character
[:escape:]
[:escape:] the <Esc>
character
[:backspace:]
[:backspace:] the <BS>
character
[:ident:]
[:ident:] identifier character (same as "\i")
[:keyword:]
[:keyword:] keyword character (same as "\k")
[:fname:]
[:fname:] file name character (same as "\f")
The square brackets in character class expressions are additional to
the square brackets delimiting a collection. For example, the
following is a plausible pattern for a UNIX filename:
"[-./[:alnum:]_~]\+". That is, a list of at least one character,
each of which is either '-', '.', '/', alphabetic, numeric, '_' or
'~'.
These items only work for 8-bit characters, except [:lower:] and
[:upper:] also work for multibyte characters when using the new
regexp engine. See two-engines. In the future these items may
work for multibyte characters. For now, to get all "alpha"
characters you can use: [[:lower:][:upper:]].
/[[=
[==]
/[[.
[..]
/\]
<Esc>
\t <Tab>
\r <CR>
(NOT end-of-line!)
\b <BS>
\n line break, see above /[\n]
\d123 decimal number of character
\o40 octal number of character up to 0o377
\x20 hexadecimal number of character up to 0xff
\u20AC hex. number of multibyte character up to 0xffff
\U1234 hex. number of multibyte character up to 0xffffffff
NOTE: The other backslash codes mentioned above do not work inside
[]!
/\%[]
E69
E70
E369
\%[] A sequence of optionally matched atoms. This always matches.
It 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]
/\<fu\%[nction]\>
/\<r\%[[eo]ad]\>
/index\%[[[]0[]]]
/\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.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>
.<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./\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 example, the pattern "a" does
not match in "càt" (where the a has the composing character 0x0300), but
"a\%C" does. Note that this does not match "cát" (where the á is character
0xe1, it does not have a compositing character). It does match "cat" (where
the a is just an a).*?,
+?, ??, {}?
0-width match atom\@= (?=atom)
0-width non-match atom\@! (?!atom)
0-width preceding match atom\@<= (?<=atom)
0-width preceding non-match atom\@<! (?<!atom)
match without retry atom\@> (?>atom)syntax-vs-match
Note that the match highlight mechanism is independent
of syntax-highlighting, which is (usually) a buffer-local
highlighting, while matching is window-local, both methods
can be freely mixed. Match highlighting functions give you
a bit more flexibility in when and how to apply, but are
typically only used for temporary highlighting, without strict
rules. Both methods can be used to conceal text.:mat
:match
:mat[ch] {group}
/{pattern}/
Define a pattern to highlight in the current window. It will
be highlighted with {group}
. Example::highlight MyGroup ctermbg=green guibg=green :match MyGroup /TODO/
{pattern}
. Watch out for using special characters,
such as '"' and '|'.{group}
must exist at the moment this command is executed.{group}
highlighting still applies when a character is
to be highlighted for 'hlsearch', as the highlighting for
matches is given higher priority than that of 'hlsearch'.
Syntax highlighting (see 'syntax') is also overruled by
matches.:highlight rightMargin term=bold ctermfg=blue guifg=blue :match rightMargin /.\%>72v/
:highlight col8 ctermbg=grey guibg=grey :match col8 /\%<8v.\%>7v/
{group}
/{pattern}/ :2match
:2mat[ch]
:2mat[ch] none
:3mat[ch] {group}
/{pattern}/ :3match
:3mat[ch]
:3mat[ch] none
Just like :match above, but set a separate match. Thus
there can be three matches active at the same time. The match
with the lowest number has priority if several match at the
same position. It uses the match id 3.
The ":3match" command is used by (older Vims) matchparen
plugin. You are suggested to use ":match" for manual matching
and ":2match" for another plugin or even better make use of
the more flexible matchadd() (and similar) functions instead.:vimgrep
enables fuzzy matching.