Searching in the current buffer
Searching for an arbitrary pattern
Vim’s standard search commands are / for forward search and ? for backward search.
To start a search from normal mode:
- press
/, - type your pattern,
- press
<CR>to perform the search.
Examples:
/foobar<CR> search forward for foobar
?foo\/bar<CR> search backward for foo/barn and N can be used to jump to the next and previous occurence:
-
Pressing
nafter a forward search positions the cursor on the next occurence, forwards. -
Pressing
Nafter a forward search positions the cursor on the next occurence, backwards. -
Pressing
nafter a backward search positions the cursor on the next occurence, backwards. -
Pressing
Nafter a backward search positions the cursor on the next occurence, forwards.
Searching for the word under the cursor
In normal mode, move the cursor to any word then press * to search forwards for the next occurrence of the word under the cursor, or press # to search backwards.
* or # search for the exact word under the cursor: searching for big would only find big and not bigger.
Under the hood, Vim uses a simple search with word boundaries atoms:
/\<big\>for*,?\<big\>for#.
g* or g# don’t search for the exact word under the cursor: searching for big would find bigger.
Under the hood, Vim uses a simple search without word boundaries atoms:
/\<big\>for*,?\<big\>for#.
execute command on lines that contain text
The :global command already has its own topic: https://stackoverflow.com/documentation/vim/3861/the-global-command