search file for text in reg ?

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

search file for text in reg ?

M Kelly
Hi,

Is there a way to search a file for the text that is in a register ?

thx always for everything vim,
-m

--
--
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: search file for text in reg ?

Tim Chase
On 2018-12-14 09:48, M Kelly wrote:
> Is there a way to search a file for the text that is in a register ?

Is the content of the register literal text or a regular expression?

If it's a regular expression (or doesn't have any regex metachars in
it), you can use

  :let @/=@a

where "@a" is the register in question.  You can then use n/N to
navigate forward/backward.

If it's literal text that might contain regexp metachars, you have to
escape them:

  :let @/=escape(@a, '.*\\$^')

(adjust the set of escaped characters accordingly; I just grabbed a
few I knew to be problematic)

-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: search file for text in reg ?

M Kelly
Hi,

>   :let @/=@a

Awesome, thank you Tim.

-m

--
--
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: search file for text in reg ?

Tony Mechelynck
In reply to this post by Tim Chase
On Fri, Dec 14, 2018 at 6:55 PM Tim Chase <[hidden email]> wrote:

>
> On 2018-12-14 09:48, M Kelly wrote:
> > Is there a way to search a file for the text that is in a register ?
>
> Is the content of the register literal text or a regular expression?
>
> If it's a regular expression (or doesn't have any regex metachars in
> it), you can use
>
>   :let @/=@a

or
     /<Ctrl-R>a
where <Ctrl-R> means "hit the Ctrl-R key combination", and replacing a
by the one-character name of the register in question. (Ctrl-R a
inserts he contens of register a in Insert and Command-line modes, see
"help c_CTRL-R".) Then hit <Enter> after the register name (also for
the :let statement).

>
> where "@a" is the register in question.  You can then use n/N to
> navigate forward/backward.
>
> If it's literal text that might contain regexp metachars, you have to
> escape them:
>
>   :let @/=escape(@a, '.*\\$^')
>
> (adjust the set of escaped characters accordingly; I just grabbed a
> few I knew to be problematic)

or
      /<Ctrl-R>a
then add escaping backslashes if and where needed by editing the
command-line before you hit <Enter>.
>
> -tim

Best regards,
Tony.

--
--
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: search file for text in reg ?

M Kelly
Hi,

>       /<Ctrl-R>a

Tony, thanks,  That is also great to know and I will use it.

thank you and everyone for vim,
-m

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