On 2/11/15 1:36 PM, Tim Chase wrote:
On 2015-02-11 13:24, Brian L. Matthews wrote:
This is probably one of those "You use vim and don't know how to do
that?!?!" things, but I'd like to be able use the contents of a
register in a search. I often have some text and want to find out
where else that text occurs. I can get the text into a register,
but then would like to search for that text.
You're close.  You can use control+R followed by the register-name to
insert that register at the search prompt.  So you can do something
like

   /<C-R>b

to insert the content of the "b" register at the search prompt.
Sweet! That's exactly what I'm looking for. I didn't know about ctrl-R, that seems like it will be generally useful.
Note
that this is interpreted as a regular expression, so if your register
contains regex metacharacters, you'd have to escape them.  Which can
be done from a mapping with something like

   :cnoremap <f4> <C-R>=escape(@b, '.\*/')<cr>

where the ".\*/" is a list of characters to escape.
Yes, I'd expect it to be treated as a regex. Thanks for the mapping though, I'll definitely use that.
You can read up more at

   :help c_CTRL-R
   :help @=
   :help escape()

if you want the ugly details.
I like ugly details :-), I just couldn't find them in this case. "ctrl-r" doesn't appear in :help /, or :help register. It does in :help search, but I don't think in a way that would have told me what I needed, even if I did know I needed ctrl-R. On the plus side, cmdline.txt (which is where :help c_CTRL-R takes you), looks quite useful, I'll have to read the whole file.

Thanks!

Brian

--
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to