A simplistic way to achieve the same result—with a little bit more of manual work—is to use :substitute
's g
and c
flags. Using g
will replace every occurrence on the line, not just the first. The c
flag prompts the user for confirmation for each substitution. See :help :s_flags
.
On the following line
To be or not to be
with the cursor on the first "be", run the command
:s/<C-R><C-W>/& a bee/cg
When asked for confirmation, reply n
to keep the first "be" and y
to replace the second one.
While this lacks the precision of Vivian's answer, I'd argue that the gc
flags are more valuable in everyday "replace all (except this)" editing tasks.
Totally unrelated non-disclaimer: originally I wanted ChatGPT to come up with a line with a repeated word but I had trouble signing in and my patience wore out after 30 seconds. No AI tools were used in writing this post. And sorry for using the lamest of Hamlet puns.