Friday, January 1, 2010

Re: Register contents within pattern?

NickC wrote:
> I want to use a register's contents as the pattern for a substitute. I
> can't find registers mentioned in the help for :sub or pattern. Is there
> a way I can do it?

From your description, yes. As you type the substitute command,
you want to use control+R followed by the register into which you
yanked it, such as

:%s/<c-r>"

to insert the scratch register in the command. It works with
named registers, so if you yank to register "z", you can use

:%s/<c-r>z

to pull its contents into the substitute. It works for any
command line, not just :substitute commands, so you can pull down
filenames, and other such things.

:help c_CTRL-R

for more info. The section following that in the help also has
suggestions for pulling in other information (such as the word
under the cursor, or the filename under the cursor).

-tim


--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: