I want to copy different strings from different lines of the file and then paste them together at once. In other words, I want to collect different words in a basket and then paste them at once. How can I do this?

2 Answers 2


Use an uppercase register when yanking (copying):


"A says to append to the a register, as opposed to "a which would replace the contents of the a register.

Once you've copied everything into the register, you can then paste it all at once with:

  • now how to clear contents of a register ?
    – John
    Jan 24, 2017 at 22:15
  • 1
    @John You can clear a register by recording an empty macro to it, like this: qaq. Alternatively, if you just want to avoid having previous junk in there, you can copy your first word using the lower case register: "ay. Remember, a and A refer to the same register, they just affect how things are added.
    – 8bittree
    Jan 24, 2017 at 22:19

You could also define your own custom operator which would yank incrementally any text-object or text covered by a motion:

fu! Incremental_yank(type, ...) abort
    if a:type ==# 'char'
        norm! `[v`]y
    elseif a:type ==# 'line'
        norm! '[V']y
    elseif a:0
        norm! gvy

    call setreg('z', @".(a:type ==# 'char' ? ' ' : ''), 'a' . getregtype('"'))
    call setreg('"', @z, getregtype('z'))

nno <silent> zy  :<C-U>set opfunc=Incremental_yank<CR>g@
xno <silent> zy  :<C-U>call Incremental_yank(visualmode(), 1)<CR>
nno <silent> zyy :<C-U>set opfunc=Incremental_yank<Bar>exe 'norm! '.v:count1.'g@_'<CR>

nno <silent> zyc :<C-U>let [@", @z] = ['', '']<CR>p

In this example, 4 key bindings are installed:

  • zy normal operator to incrementally yank a text-object or motion
  • zyy similar operator which works on lines
  • zy similar operator which works on visual selection
  • zyc normal command to empty the registers " and z; useful before beginning to yank a sequence of texts

With it, you could:

  • copy some words hitting zyiw on the first word, then repeat the operation with the dot command on the next ones
  • copy some lines hitting zyy on the first one, then repeat the operation with the dot command on the next ones
  • copy some visual selections, hitting zy on each of them

The current code clutters the z register, if you prefer using another register, like x for example, you could change the following lines:

call setreg('z', @", 'a' . getregtype('"'))                call setreg('x', @", 'a' . getregtype('"'))
             ^                                                          ^
call setreg('"', @z, getregtype('z'))                 →    call setreg('"', @x, getregtype('x'))
                  ^              ^                                           ^              ^
nno <silent> zyc :<C-U>let [@", @z] = ['', '']<CR>p        nno <silent> zyc :<C-U>let [@", @x] = ['', '']<CR>p
                                 ^                                                          ^

For more information, see:

:h g@
:h getregtype()
:h setreg()

enter image description here

  • What's that program?
    – Plakhoy
    Feb 1, 2017 at 17:44
  • byzanz-record and screenkey Feb 2, 2017 at 1:30
  • This is awesome! Could this be changed in order to add a loop to yank-append on multiple visual selections? Say I want to yank all sections no a markdown file. I could /^#\s.\+ and then do zyv for instance!
    – Luciano
    May 6, 2020 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.