search
* / #
* searches forward for the whole word under the cursor; # searches backward. Zero typing needed — put your cursor on the identifier and hit *.
* # (normal mode) Variations
| Keystroke | Effect |
|---|---|
| g* | Search forward for word under cursor WITHOUT the whole-word boundary |
| g# | Backward version of g* |
| 3* | Jump to the third occurrence of the current word |
Examples
* Highlight and jump to next occurrence of current identifier
# Jump to previous occurrence
*N * then N — mark current word without moving cursor
Gotcha
By default * anchors with \
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'.
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.
: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).