search
n / N
n jumps to the next match of the last search, N to the previous. Direction is relative to the ORIGINAL search direction — if you searched with ?, then n goes backward.
n N (normal mode) Variations
| Keystroke | Effect |
|---|---|
| 3n | Jump forward 3 matches |
| :noh | Clear the search highlight (until next search) |
| gn | Visually select the next match — pairs beautifully with c/d/y |
Examples
/foo<Enter>nn Find foo and jump to the third occurrence
cgn bar<Esc>. Change next match to bar; . repeats on each next match
N Jump to previous match
Gotcha
n's direction depends on whether the search started with / or ? — after ?foo, n goes UP the file. Use / to reset direction.
Related
/ and ?
/ searches forward for a regex, ? searches backward. After the search, press n to jump to the next match and N for the previous — searching is a first-class motion, so d/foo deletes up to the next 'foo'.
* / #
* searches forward for the whole word under the cursor; # searches backward. Zero typing needed — put your cursor on the identifier and hit *.
.
Repeats the last CHANGE (any command that modified the buffer, including the whole insert-mode session that followed it). The single most-loved Vim feature — learn to structure edits so that '.' does the work for the next N occurrences.
:s and :%s
Substitute (find-and-replace) within a range of lines. Without a range :s works on the current line only; :%s uses % as shorthand for the whole file (equivalent to :1,$s). Add flags like g (all matches per line) and c (confirm).