Goal: Select multiple words, one at a time, then replace them all.
I'm new to Vim,Vim; I come from Visual Studio. I would like to achieve one important feature that helped me a lot in my productivity: Select multiple words, one at a time, and then replace them all.
I know there is a Vim way of selecting and replacing using:
:% s/target-word/replacement/gc
But as you can see it's still a lot to write compared to its counterpart in VS.Code Code. Could someone help me with a vim script or a plugin to achieve this in the most similar way?
- imagine that I already have selected the word with
viw
, for example. - then I want to have a single command to select the next match.
- then start writing and see those changes written in real-time or after hitting Esc
Esc
.
Thanks for any guidance on this.
[EDIT]
As Martin Tournoij explains it, I can use the star *
operator and then the %s//replacement
, this is great.
Now... how can I map this to a nmap
, nnremap
or inoremap
(that I yat don't fully understand...)
Let's say I already make a selection with *
then... what do I do to avoid typing :%s//replacement
just a lead key and then the replacement, is it possible?
[Edit] Accepted answer
ThankThanks D. Ben Knoble,Knoble; you provided to me the more convenient and practical answer. As the main goal is to change a word locally, the combination *gn*cgn
Is perfect.
As I'm changing the also the current word and *
jumps me to the next match, what I add to go back to that word is Ctrl + N
.
* Ctrl + N cgn
then .
Thanks to this amazing community! Cheers.