All levels

Search & Precise Navigation

Jump straight to what you want with search and in-line motions.

Levels 02 / 12
  1. 00 Vim Modes
  2. 01 Basic Movement
  3. 02 Search & Precise Navigation
  4. 03 Inserting Text
  5. 04 Operators + Motions
  6. 05 Quick Editing
  7. 06 Visual Mode
  8. 07 Commenting Code
  9. 08 Multipliers
  10. 09 File & Buffer Navigation
  11. 10 Macros
  12. 11 Search & Replace
  13. 12 Marks

Motions get you to the right neighborhood. Search drops you on the doorstep. Once / and f are in your fingers, you stop counting js and ws and just go straight to the thing you’re looking at. Two flavors here: search across the file, and search within the line. You’ll reach for both constantly.

/text  ?text  → search forward / backward
n  N          → next / previous match
*  #          → search word under cursor forward / backward
:noh          → clear search highlight

* is one of the most useful commands in Vim: put your cursor on a word, press *, and jump through every occurrence with n.

f{char}  → jump onto the next {char} on the line
t{char}  → jump just before {char}
F  T     → same, but backward
;  ,     → repeat last f/F/t/T forward / backward

f lands on the character, t lands before it. Both also work as motions: dt, deletes up to the next comma, df) deletes through the next ). That’s the grammar in action.

Plain search vs word boundaries

  1. Type /count: it matches count, discount, accountNumber, recount.
  2. Put the cursor on the word count and press *: it matches only the exact word.
  3. /count is a plain substring search; * adds word boundaries automatically.
i to type · hjkl to move · Tab leaves the editor

goal Know when to use /word vs * for precise matching.

Within-line search with f and t

  1. Press 0 to go to the start of the line.
  2. Press f(: jump onto the (.
  3. Press f,: jump to the first ,.
  4. Press ; twice: repeat to the next commas.
  5. Press ,: jump back to the previous comma.
  6. Press 0, then t): land just before the ).
i to type · hjkl to move · Tab leaves the editor

goal Use ; and , to repeat the last f/t in either direction.

Combining f/t with operators

On line 1:

  1. Press 0, then fb to land on base.
  2. Press dt,: delete up to (but not including) the first comma. base vanishes, the comma stays.

On line 2:

  1. Press 0, then f" to jump to the opening quote.
  2. Press df,: delete from the quote through the first comma. Notice f includes the target, t stops short of it.
i to type · hjkl to move · Tab leaves the editor

goal Use f/t as motions for operators, not just for navigation.

Search-driven audit

  1. Put the cursor on userId and press *: jump through each occurrence with n.
  2. Press N to navigate backward.
  3. Search /Error and visit both occurrences with n.
  4. Put the cursor on find and press *. How many times does it appear?
i to type · hjkl to move · Tab leaves the editor

goal Use * and n/N to quickly count how often something appears.