How to use search string in search replace?

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

How to use search string in search replace?

Kennedy, Marcus A.

So I was searching through some ugly build commands when I realized that
I needed to go from search mode to command mode to delete part of the
output text I was looking at.  Going from command mode with a
:%s/<search String>/<replace text> to search mode will allow you to
press up arrow to get your last :%s/ search string, but it doesn't work
the other way.  Is there an easy way within vim to get that string back
from search mode to command mode?  A quick google search was unrevealing
(though I don't have access to all hits from my present location).

Just so you know, I had to shift-select-right-click to copy the text
from Konsole.

Thanks,
Andy


--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5ADFF93892EDB147B66FCBABC8E4F27F54C58CDE%40ARSPAPPEXCH03.
Reply | Threaded
Open this post in threaded view
|

Re: How to use search string in search replace?

Salman Halim
If you specify no search string in the s command, it uses the last search automatically:

%s//replacement...

--

Salman

On Tue, 9 Feb 2021, 19:56 Kennedy, Marcus A., <[hidden email]> wrote:

So I was searching through some ugly build commands when I realized that
I needed to go from search mode to command mode to delete part of the
output text I was looking at.  Going from command mode with a
:%s/<search String>/<replace text> to search mode will allow you to
press up arrow to get your last :%s/ search string, but it doesn't work
the other way.  Is there an easy way within vim to get that string back
from search mode to command mode?  A quick google search was unrevealing
(though I don't have access to all hits from my present location).

Just so you know, I had to shift-select-right-click to copy the text
from Konsole.

Thanks,
Andy


--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5ADFF93892EDB147B66FCBABC8E4F27F54C58CDE%40ARSPAPPEXCH03.

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEfksqh02hCbfZJYC-b0c7ui2ne_B0mGNtOg1WPcFv%3DNyQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to use search string in search replace?

Tim Chase
In reply to this post by Kennedy, Marcus A.
On 2021-02-10 00:56, Kennedy, Marcus A. wrote:
> So I was searching through some ugly build commands when I realized
> that I needed to go from search mode to command mode to delete part
> of the output text I was looking at.  Going from command mode with a
> :%s/<search String>/<replace text> to search mode will allow you to
> press up arrow to get your last :%s/ search string, but it doesn't
> work the other way.  Is there an easy way within vim to get that
> string back from search mode to command mode?  A quick google
> search was unrevealing (though I don't have access to all hits from
> my present location).

I'm not quite certain which text you're trying to recall since there's
not really a "search mode".  It would help to have a more explicit
sequence of the commands you're trying to run, possibly with a "magic
happens here to do XYZ".

A few pointers to places that might be useful in the meantime:

  :help last-pattern
  vim remembers your most recent search and can reuse it

  :help c_CTRL-R
  lets you insert the contents of a register (including the @/ search
  register) at the current point in an Ex command

-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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210209193429.08f0ad80%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

RE: [EXTERNAL] Re: How to use search string in search replace?

Kennedy, Marcus A.
In reply to this post by Salman Halim

> -----Original Message-----
> From: [hidden email] <[hidden email]> On
> Behalf Of Salman Halim
> Sent: Tuesday, February 9, 2021 7:11 PM
> To: Vim Users <[hidden email]>
> Subject: [EXTERNAL] Re: How to use search string in search replace?
>
> If you specify no search string in the s command, it uses the last search
> automatically:
>
> %s//replacement...

Ah yes!  I didn't know that!  That is perfect!

Thanks!
Andy

>
>
> --
>
> Salman
>
> On Tue, 9 Feb 2021, 19:56 Kennedy, Marcus A.,
> <[hidden email] <mailto:[hidden email]> >
> wrote:
>
>
>
> So I was searching through some ugly build commands when I
> realized that
> I needed to go from search mode to command mode to delete part
> of the
> output text I was looking at.  Going from command mode with a
> :%s/<search String>/<replace text> to search mode will allow you to
> press up arrow to get your last :%s/ search string, but it doesn't work
> the other way.  Is there an easy way within vim to get that string back
> from search mode to command mode?  A quick google search was
> unrevealing
> (though I don't have access to all hits from my present location).
>
> Just so you know, I had to shift-select-right-click to copy the text
> from Konsole.
>
> Thanks,
> Andy
>
>
> --
> --
> 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]
> <mailto:vim_use%[hidden email]> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vim_use/5ADFF93892EDB147B66FCBAB
> C8E4F27F54C58CDE%40ARSPAPPEXCH03.
>
>
> --
> --
> 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].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vim_use/CANuxnEfksqh02hCbfZJYC-
> b0c7ui2ne_B0mGNtOg1WPcFv%3DNyQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/vim_use/CANuxnEfksqh02hCbfZJYC-
> b0c7ui2ne_B0mGNtOg1WPcFv%3DNyQ%40mail.gmail.com?utm_medium=e
> mail&utm_source=footer> .

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5ADFF93892EDB147B66FCBABC8E4F27F54C5EDDD%40ARSPAPPEXCH03.
Reply | Threaded
Open this post in threaded view
|

RE: [EXTERNAL] Re: How to use search string in search replace?

Kennedy, Marcus A.
In reply to this post by Tim Chase

> -----Original Message-----
> From: [hidden email] <[hidden email]> On
> Behalf Of Tim Chase
> Sent: Tuesday, February 9, 2021 7:34 PM
> To: Kennedy, Marcus A. <[hidden email]>
> Cc: [hidden email]
> Subject: [EXTERNAL] Re: How to use search string in search replace?
>
> On 2021-02-10 00:56, Kennedy, Marcus A. wrote:
> > So I was searching through some ugly build commands when I realized
> > that I needed to go from search mode to command mode to delete part of
> > the output text I was looking at.  Going from command mode with a
> > :%s/<search String>/<replace text> to search mode will allow you to
> > press up arrow to get your last :%s/ search string, but it doesn't
> > work the other way.  Is there an easy way within vim to get that
> > string back from search mode to command mode?  A quick google search
> > was unrevealing (though I don't have access to all hits from my
> > present location).
>
> I'm not quite certain which text you're trying to recall since there's not really
> a "search mode".  It would help to have a more explicit sequence of the
> commands you're trying to run, possibly with a "magic happens here to do
> XYZ".

/\/path\/to\/some\/location
:%s///    <- Here I wanted to use the PREVIOUS search from the line above.

And, for clarification, what exactly do you call the mode when you press "/"
to search for a string in your document?

Thanks to Salman, I now know how to do that!  (if I can remember it).

Thanks,
Andy

>
> A few pointers to places that might be useful in the meantime:
>
>   :help last-pattern
>   vim remembers your most recent search and can reuse it
>
>   :help c_CTRL-R
>   lets you insert the contents of a register (including the @/ search
>   register) at the current point in an Ex command
>
> -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].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vim_use/20210209193429.08f0ad80%40
> bigbox.attlocal.net.

--
--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5ADFF93892EDB147B66FCBABC8E4F27F54C5EDF1%40ARSPAPPEXCH03.