Pattern Search

/ searches forward, ? searches back. n and N step through matches.

Keys: /, ?, n, N

/pattern searches forward; ?pattern searches backward. n repeats the search in the original direction; N reverses it. Search is one of Vim's most powerful motions.

Vim's search is two-stage: type / (or ?) at the cursor's current line, type the pattern, press Enter. Cursor jumps to the first match. n for the next match, N for the previous.

Search forward
KeyNote
/
{pattern}
Enter
Search backward
KeyNote
?
{pattern}
Enter
Repeat search in same direction
KeyNote
n
Repeat search in opposite direction
KeyNote
N
/ โ€” search forward
? โ€” search backward
n โ€” next match
N โ€” previous match

Reference

Key Action
/{pattern}Enter Forward search
?{pattern}Enter Backward search
n / N Next / previous (in original direction)
/Enter Repeat last search forward
?Enter Repeat last search backward
:noh Clear highlights
Ctrl-O / Ctrl-I Jump back / forward (search jumps land here)

Worked example โ€” /word and n / N

Forward search, then jump through hits.

Step 1 ยท
search.pattern
Step 2 ยท /cat ยท / shows search prompt at the bottom.
/ shows search prompt at the bottom.
Step 3 ยท Enter ยท Enter โ€” first match highlighted.
Enter โ€” first match highlighted.
Step 4 ยท n ยท n โ€” next match.
n โ€” next match.

N goes back. // repeats with the same pattern; ? searches backward.

โ–ถ Try this in the simulator

See also: Word Search, Substitute ({key::s}), Special Registers, The Jump List