How to search for text in Vim
/?n*Type /, the text you want, then Enter. The cursor jumps to the next match. ? does the same backwards.
Press n for the next match and N for the previous one. * searches for the word under the cursor, as a whole word.
Worked example
Find draft, then the next one.
/draft then Enter lands on the first draft. n repeats the search and reaches the second.
Commands
- /text
- Search forward. Press Enter to go.
- ?text
- Search backward.
- n
- Go to the next match, in the same direction.
- N
- Go to the previous match.
- *
- Search forward for the word under the cursor.
- #
- Search backward for the word under the cursor.
- d/text
- Delete up to the match. The match itself stays.
On one line: f and t
For a character on the current line, f is faster. f, jumps to the next comma. t, stops just before it. F and T look to the left. ; repeats the last one and , repeats it in the other direction.
- f,
- Jump to the next comma on the line.
- t,
- Jump to just before it.
- ;
- Repeat the last f or t.
- ,
- Repeat it the other way.
- dt,
- Delete up to the comma and keep the comma.
Exceptions
- /cat also finds
catalog. * matches whole words only, so it skips it. - Search wraps around: past the last match it starts again at the top.
- Search is case sensitive:
/agendaskipsAgenda. - What you type is a pattern, not plain text. A dot matches any character, so
/a.bfindsaxb. - Esc at the search prompt cancels the search. The cursor stays where it was.
- f and t never leave the line. If there is no match, the cursor stays.