Reputation: 276
Is there a simple way (without too many keystrokes), to substitute the next occurrence of a pattern (in the line or in the whole document, both would be interesting), starting from the cursor position?
So far, I've only come up with selecting onwards, going to normal mode, and doing :s/\%Vpattern/rep
. It's too cumbersome. Perhaps there's a nice way to select the next occurrance of a pattern, and then one can "change" the selection?
Thanks
Upvotes: 2
Views: 777
Reputation: 1681
You can use the confirm option with your substitution. Use the command
:%s/pattern/replacement/gc
It will take you through each occurrence of the pattern. Type y to replace, n to move on without replacing, and q to quit the search.
Upvotes: 4
Reputation: 28169
You can use gn
Just search for the pattern, using /
Select using gn
Once selected, you can perform any action on it. Like y
to copy, c
to change etc
:h gn
Upvotes: 2