level 02

Search & Precise Navigation

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

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.

File-wide search

  1. Type /Name and Enter — find the first occurrence.
  2. Press n repeatedly to visit each match.
  3. Press N to go backward.
  4. Put the cursor on fullName and press * to search that exact word.
  5. Press :noh and Enter to clear the highlight.
normalpress i to type · hjkl to move

goal Move through matches with n and N without scrolling.

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.
normalpress i to type · hjkl to move

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 ).
normalpress i to type · hjkl to move

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.
normalpress i to type · hjkl to move

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?
normalpress i to type · hjkl to move

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