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.
File-Wide Search
/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.
Within-Line Search
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
- Type
/Nameand Enter — find the first occurrence. - Press
nrepeatedly to visit each match. - Press
Nto go backward. - Put the cursor on
fullNameand press*to search that exact word. - Press
:nohand Enter to clear the highlight.
goal Move through matches with n and N without scrolling.
Plain search vs word boundaries
- Type
/count— it matchescount,discount,accountNumber,recount. - Put the cursor on the word
countand press*— it matches only the exact word. /countis a plain substring search;*adds word boundaries automatically.
goal Know when to use /word vs * for precise matching.
Within-line search with f and t
- Press
0to go to the start of the line. - Press
f(— jump onto the(. - Press
f,— jump to the first,. - Press
;twice — repeat to the next commas. - Press
,— jump back to the previous comma. - Press
0, thent)— land just before the).
goal Use ; and , to repeat the last f/t in either direction.
Combining f/t with operators
On line 1:
- Press
0, thenfbto land onbase. - Press
dt,— delete up to (but not including) the first comma.basevanishes, the comma stays.
On line 2:
- Press
0, thenf"to jump to the opening quote. - Press
df,— delete from the quote through the first comma. Noticefincludes the target,tstops short of it.
goal Use f/t as motions for operators, not just for navigation.
Search-driven audit
- Put the cursor on
userIdand press*— jump through each occurrence withn. - Press
Nto navigate backward. - Search
/Errorand visit both occurrences withn. - Put the cursor on
findand press*. How many times does it appear?
goal Use * and n/N to quickly count how often something appears.