Visual + global substitution on part of a line replaces every occurance, even outside the selected region

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Visual + global substitution on part of a line replaces every occurance, even outside the selected region

David Woodfall
If I visually highlight part of a line and do a substitution using /g
it replaces every occurrence in the line, even outside the visual
range.

Is there a way around this?

Thanks

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Visual + global substitution on part of a line replaces every occurance, even outside the selected region

Tim Chase
On 2018-02-22 04:25, David Woodfall wrote:
> If I visually highlight part of a line and do a substitution
> using /g it replaces every occurrence in the line, even outside the
> visual range.
>
> Is there a way around this?

You want the "\%V" atom:

  :help /\%V

so you'd search for

  /\%Vpattern\%V

(you can omit one or the other if you only care whether it
starts/ends within the visual region)

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Visual + global substitution on part of a line replaces every occurance, even outside the selected region

David Woodfall
>On 2018-02-22 04:25, David Woodfall wrote:
>> If I visually highlight part of a line and do a substitution
>> using /g it replaces every occurrence in the line, even outside the
>> visual range.
>>
>> Is there a way around this?
>
>You want the "\%V" atom:
>
>  :help /\%V
>
>so you'd search for
>
>  /\%Vpattern\%V
>
>(you can omit one or the other if you only care whether it
>starts/ends within the visual region)
>
>-tim

Thanks. That did it.

Dave

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.