Saturday, December 15, 2018

Re: search file for text in reg ?

On Fri, Dec 14, 2018 at 6:55 PM Tim Chase <vim@tim.thechases.com> 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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: