Appending to register.

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

Appending to register.

Jeremy Eliosoff
Hello.

Does anyone know of a way to append yanked text to the content of a
pre-existing register?  This would often be handy for going through a
file and accumilating a bunch of snippets to be deposited somewhere
else, without having to keep track of a bunch of different registers
or putting + re-yanking all the time.

Thanks,
Jeremy.
Reply | Threaded
Open this post in threaded view
|

Re: Appending to register.

Mike McNally-2
> Does anyone know of a way to append yanked text to the content of a
> pre-existing register?  This would often be handy for going through a
> file and accumilating a bunch of snippets to be deposited somewhere
> else, without having to keep track of a bunch of different registers
> or putting + re-yanking all the time.

Capitalize the register name (i.e., A instead of a), and the yank will
append. That's vi behavior from the dawn of time.

Thus:
  "ayy    yanks the current line and overwrites register a
  "Ayy    appends the current line to register a

   
--
[ you are my main foo ] Mike McNally -- [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Appending to register.

Charles E Campbell Jr
In reply to this post by Jeremy Eliosoff
Quoting Jeremy Eliosoff <[hidden email]>:


> Does anyone know of a way to append yanked text to the content of a
> pre-existing register?  This would often be handy for going through a
> file and accumilating a bunch of snippets to be deposited somewhere
> else, without having to keep track of a bunch of different registers
> or putting + re-yanking all the time.

Try yanking to the capitalized version of the register.  From the help
for  :he "a

4. Named registers "a to "z or "A to "Z                 *quote_alpha* *quotea*
Vim fills these registers only when you say so.  Specify them as lowercase
letters to replace their previous contents or as uppercase letters to append
to their previous contents...

Its in the help.  Its always in the help!  Now, finding where it is in that
help is another issue...

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: Appending to register.

Tim Chase-2
In reply to this post by Jeremy Eliosoff
> Does anyone know of a way to append yanked text to the content
> of a pre-existing register?  This would often be handy for
> going through a file and accumilating a bunch of snippets to
> be deposited somewhere else, without having to keep track of a
> bunch of different registers or putting + re-yanking all the
> time.

If you are using named registers (the letters "a-z"), you can
simply use the uppercase cousin to append (rather than replace,
which the standard lowercase version does) to the existing
register. Thus, you can simply use

        "Ayy

to append the current line to register "a" instead of

        "ayy

However, for the default register, there's no native way to keep
appending to it, AFAIK. If the lines in question can be matched
by a regexp, and you want the whole line appended, you can use
the idiom

        :let @a='' | g/regexp/y A

which will append every line matching "regexp" to register A.
This also works with the default register via a little more
convolution:

        :let @"='' | g/regexp/let @"=@" . line(".")

and the same can be done with the system clipboard, using @*
instead of @"

If you just want a sub-portion of the line, you can go even
further, tweaking that previous one to become something like this
(untested...beware having the proper levels of escaping of
back-slashes)

        :let @a='' | g/regexp/let @a=@a . substitute(getline("."),
".\\{-}\\(regexp\\).*", "\\1", "")

You may have to tweak them to include linebreaks as desired by
appending the following to the previous example

        ."\n"

For more info, see

        :help quote_alpha
        :he expr-register
        :he :g
        :he getline()
        :he substitute()
        :he /\(

Hope this gives you some avenues to explore and hopefully make
your job easier.

-tim




Reply | Threaded
Open this post in threaded view
|

Re: Appending to register.

Eric Arnold

> > Does anyone know of a way to append yanked text to the content
> > of a pre-existing register?  This would often be handy for
>
[...]
>
> However, for the default register, there's no native way to keep
> appending to it, AFAIK. If the lines in question can be matched

Another way to go is to do all your work with an [A-Z] register, and then
copy it, i.e. to the clipboard register:

    :let @* = @a

Reply | Threaded
Open this post in threaded view
|

Re: Appending to register.

A.J.Mechelynck
In reply to this post by Jeremy Eliosoff
Jeremy Eliosoff wrote:

> Hello.
>
> Does anyone know of a way to append yanked text to the content of a
> pre-existing register?  This would often be handy for going through a
> file and accumilating a bunch of snippets to be deposited somewhere
> else, without having to keep track of a bunch of different registers
> or putting + re-yanking all the time.
>
> Thanks,
> Jeremy.
>
>
>
>

In most versions of Vim, you can append to registers "a to "z by using
an uppercase letter ("A instead of "a, for instance, or :redir @A
instead of :redir @a).

In addition, in Vim version 7, some commands can append to any writable
register: for instance, to redirect output messages so that they are
appended to the clipboard, you would use

        :redir @*>>

This second method is not available in Vim 6 and earlier.


Best regards,
Tony.