Skip to main content
edited tags
Link
Martin Tournoij
  • 63.3k
  • 26
  • 199
  • 274
deleted 529 characters in body
Source Link
D. Ben Knoble
  • 27.7k
  • 3
  • 31
  • 68

Goal: Select multiple words, one at a time, then replace them all.

visual studio feature select and replace

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 EscEsc.

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.

enter image description here

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 .

enter image description here

Thanks to this amazing community! Cheers.

Goal: Select multiple words, one at a time, then replace them all.

visual studio feature select and replace

I'm new to 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. 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.

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.

enter image description here

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

Thank D. Ben Knoble, you provided to me the more convenient and practical answer. As the main goal is to change a word locally, the combination *gn 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 .

enter image description here

Thanks to this amazing community! Cheers.

Goal: Select multiple words, one at a time, then replace them all.

visual studio feature select and replace

I'm new to 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 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. 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.

[Edit] Accepted answer

Thanks D. Ben Knoble; you provided to me the more convenient and practical answer. As the main goal is to change a word locally, the combination *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 .

enter image description here

Became Hot Network Question
Add accepted answer
Source Link
Sam
  • 301
  • 1
  • 3
  • 10

Goal: Select multiple words, one at a time, then replace them all.

visual studio feature select and replace

I'm new to 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. 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.

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.

enter image description here

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?

Thanks again![Edit] Accepted answer

CheersThank D. Ben Knoble, you provided to me the more convenient and practical answer. As the main goal is to change a word locally, the combination *gn 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 .

enter image description here

Thanks to this amazing community! Cheers.

Goal: Select multiple words, one at a time, then replace them all.

visual studio feature select and replace

I'm new to 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. 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.

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.

enter image description here

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?

Thanks again!

Cheers.

Goal: Select multiple words, one at a time, then replace them all.

visual studio feature select and replace

I'm new to 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. 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.

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.

enter image description here

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

Thank D. Ben Knoble, you provided to me the more convenient and practical answer. As the main goal is to change a word locally, the combination *gn 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 .

enter image description here

Thanks to this amazing community! Cheers.

Add partial answer and clarifications.
Source Link
Sam
  • 301
  • 1
  • 3
  • 10
Loading
Source Link
Sam
  • 301
  • 1
  • 3
  • 10
Loading