Another option is to use gn
:
Search forward for the last used search pattern, like with
n
, and start Visual mode to select the match.
If the cursor is on the match, visually selects it.
If an operator is pending, operates on the match.
E.g., "dgn" deletes the text of the next match.
If Visual mode is active, extends the selection until the end of the
next match.
Note: Unlike n
the search direction does not depend on the previous search command.
So if you have FOO
as last search expression, you can replace its next match with BAR
typing cgnBAR<Esc>
, and repeat for the following matches with .
.
If you want to set the word under the cursor as search expression you can type *N
(or *#
) to search for the next match and come back.
For example, if your cursor is under the first FOO
in this line:
<div class="FOO"><span id="FOO"><b>FOO:</b> FOO</span></div>
and you type *NcgnBAR<Esc>...
, you end up with this:
<div class="BAR"><span id="BAR"><b>BAR:</b> BAR</span></div>
n
works for meb
goes back to default (beginning of the word)#
works for me as expected, which goes back to the previous term.n
for next andN
for previous. It's written on my keyboard so I don't know how I got it wrong.