*pattern.txt* For Vim version 8.2. Last change: 2022 Mar 04
VIM REFERENCE MANUAL by Bram Moolenaar
Patterns and search commands *pattern-searches*
The very basics can be found in section |03.9| of the user manual. A few more
explanations are in chapter 27 |usr_27.txt|.
1. Search commands |search-commands|
2. The definition of a pattern |search-pattern|
3. Magic |/magic|
4. Overview of pattern items |pattern-overview|
5. Multi items |pattern-multi-items|
6. Ordinary atoms |pattern-atoms|
7. Ignoring case in a pattern |/ignorecase|
8. Composing characters |patterns-composing|
9. Compare with Perl patterns |perl-patterns|
10. Highlighting matches |match-highlight|
11. Fuzzy matching |fuzzy-matching|
==============================================================================
1. Search commands *search-commands*
*/*
/{pattern}[/]<CR> Search forward for the [count]'th occurrence of
{pattern} |exclusive|.
/{pattern}/{offset}<CR> Search forward for the [count]'th occurrence of
{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}<CR> Search forward for the [count]'th occurrence of the
latest used pattern |last-pattern| with new
|{offset}|. If {offset} is empty no offset is used.
*?*
?{pattern}[?]<CR> Search backward for the [count]'th previous
occurrence of {pattern} |exclusive|.
?{pattern}?{offset}<CR> Search backward for the [count]'th previous
occurrence of {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}<CR> Search backward for the [count]'th occurrence of the
latest used pattern |last-pattern| with new
|{offset}|. If {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-pattern|
*N*
N Repeat the latest "/" or "?" [count] times in
opposite direction. |last-pattern|
*star* *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.
*#*
# 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).
*gstar*
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.
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