sponsor Vim development Vim logo go to HTTPS page Vim Book Ad

RepeatableYank : Repeatable appending yank to a named register.

 script karma  Rating 5/2, Downloaded by 483    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
script type
Text fragments can be collected and accumulated by first yanking into a
lowercase register, and then subsequently yanking into the uppercase variant.
The problem is that the register must be specified on every yank command, and
one accidental omission of uppercasing the register results in the
irrecoverable loss of all fragments collected so far.

This can be somewhat remedied by enabling the non-default cpo-y setting,
which allows a repeat of a yank (plus remembered last register) via .

This plugin instead offers an alternative yank command gy, which allows to
specify the accumulator register only once on its initial use, can then be
repeated as an operator, linewise, in visual mode and via ., and enhances
some yank semantics for special cases.  For example, subsequent blockwise
yanks are merged as blocks to the right, instead of added below the existing
text blocks.

["x]gy{motion}          Yank {motion} text into register x.
["x][count]gyy          Yank [count] lines into register x.
{Visual}["x]gy          Yank the selected text into register x.

                        Subsequent gy commands without an explicit register
                        and command repeats via . will append (in the case
                        of named registers {a-zA-Z}) the text to / overwrite
                        (for registers {0-9*+~/-}) the previously used
                        register x, until another register is explicitly
                        Therefore, you can gradually build up text in a named
                        register, or easily update the system clipboard
                        without having to repeat the register on every yank.

                        Subsequent blockwise yanks are merged as blocks to the
                            ab -> ab12
                            cd    cd34
                        instead of added below the existing text blocks:
                            ab -> ab
                            cd    cd

["x]gly{motion}         Yank {motion} text as a new line into register x.
{Visual}["x]gly         Yank the selected text as a new line into register x.
                        When repeated, the text will be automatically
                        separated from the existing contents by a newline
                        character. This is useful for collecting individual
                        words (without surrounding whitespace), or other
                        phrases when you intend to work on them as separate

                        You can also use this mapping to avoid the special
                        RepeatableYank-block-merge behavior.

Start by yanking "an entire line" into register a:
   an entire line

Add "another line" to the same register a without specifying it again:
   an entire line
    another line

Add "word1" and "word2"; even though the register is now of linewise type,
these are added on a single line:
    gyw w.
   an entire line
    another line
    word1 word2

Now, let's yank a vertical block of "ABC" into another register:
    <C-V>2j "bgy
Another vertical block of "123" is appended blockwise to the right:

You can build up multiple registers in parallel. To switch to another register
without starting over, just specify the uppercase register name:
   an entire line
    another line
    word1 word2
    +addition after register switch

This is an example of gly:
Start by yanking "word1" into register a:

Add "word2" and "word3", but on separate lines, so that the register contents
don't turn into a mess of "word1word2word3":
install details
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim RepeatableYank*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.008 or
- repeat.vim (vimscript #2136) plugin (optional).
- visualrepeat.vim (vimscript #3848) plugin (version 2.00 or higher; optional)

For a permanent configuration, put the following commands into your vimrc:

Since you don't need this plugin to repeat yanks to the unnamed register (just
use the built-in y), register "a is used as the default register, i.e. when
you use gy for the first time without explicitly specifying a register. To
change this default to another register (e.g. the clipboard), use:
    let g:RepeatableYank_DefaultRegister = '+'

If you want to use different mappings, map your keys to the
<Plug>RepeatableYank... mapping targets _before_ sourcing the script (e.g. in
your vimrc):
    nmap <Leader>y  <Plug>RepeatableYankOperator
    nmap <Leader>yy <Plug>RepeatableYankLine
    xmap <Leader>y  <Plug>RepeatableYankVisual
    nmap <Leader>ly <Plug>RepeatableYankAsLineOperator
    xmap <Leader>ly <Plug>RepeatableYankAsLineVisual

If you don't need the gly mappings introduced in version 1.10:
    nmap <Plug>DisableRepeatableYankAsLineOperator <Plug>RepeatableYankAsLineOperator
    xmap <Plug>DisableRepeatableYankAsLineVisual   <Plug>RepeatableYankAsLineVisual

Rating scripts is only available on the HTTPS page

script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
RepeatableYank-1.20.vmb.gz 1.20 2013-11-21 7.0 Ingo Karkat - Use optional visualrepeat#reapply#VisualMode() for normal mode repeat of a visual mapping. When supplying a [count] on such repeat of a previous linewise selection, now [count] number of lines instead of [count] times the original selection is used.
- Avoid changing the jumplist.
- Add dependency to ingo-library (vimscript #4433). *** You need to separately install ingo-library (vimscript #4433) version 1.008 (or higher)! ***
RepeatableYank-1.10.vmb.gz 1.10 2012-12-27 7.0 Ingo Karkat - ENH: Add alternative gly mapping to yank as new line.
- FIX: When appending a block consisting of a single line, the merge doesn't capture the new block at all.
RepeatableYank-1.00.vmb.gz 1.00 2012-09-24 7.0 Ingo Karkat Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo