I am copying multiple lines from different parts.
I can for example do
3yy
to copy the 3 next lines.
Then I would like to scroll a bit and add 5 more lines:
5yy
and so on. At the end, I want to paste all lines (in this case 8)
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI am copying multiple lines from different parts.
I can for example do
3yy
to copy the 3 next lines.
Then I would like to scroll a bit and add 5 more lines:
5yy
and so on. At the end, I want to paste all lines (in this case 8)
You can append to the named registers "a
through "z
, in which case you use the lowercase versions of the registers to overwrite/replace their contents and the uppercase version to append to their contents.
So you can use "a3yy
(or 3"ayy
) for the initial yank of 3 lines, then "A5yy
(or 5"Ayy
) to append the 5 next lines to that same register, which you can then put using "ap
(or "Ap
also works.)
See :help "a
for details.
A neat trick to use when appending to named registers is that you can use the q
command (which records macros) to empty the registers. For example, qaq
will clear register "a
. (It starts recording a macro into register "a
, and then the second q
ends the recording right away.) By clearing the register first, you can then use the uppercase register for appending on the first yank, which can be useful if you're using a repeated command such as a macro or a :g
command to yank multiple lines.