How do I search backward for text in Vim?
Answer
?{pattern}
Explanation
The ? command searches backward from the cursor position. It works exactly like / but in reverse.
How it works
- Press
?to open the backward search prompt - Type your search pattern
- Press
<CR>to find the previous match before the cursor
Example
line one
line two
line three
With the cursor on line three, typing ?one<CR> jumps to one on the first line.
Tips
ncontinues searching in the backward directionNreverses to search forward?also wraps around the beginning of the file- You can use the same regex patterns as with
/