How can I yank multiple lines into a register?

Use 3Y to yank 3 lines into the default register; "i3Y for yanking into register i.

Also, my favorite way is not to count the lines I want to yank, but to select them in visual mode via V and moving commands, and then hit y to yank it or "_y to yank into a register.

Also, I have just tried selecting multiple lines in Visual Line mode and yanking into not-default register, e.g. Vjjj"oy — and it works.


From anywhere within the file, you can use the following.

:2,5y a

Yank lines 2 - 5. INTO REGISTER a

:7pu a

Paste register a under line 7.


Use m to mark the start, with a buffer name (so you might type mx). Move your cursor down to where you want to stop copying, and type y'x (or d'x if you're cutting and pasting). Then move the to the point where you want to paste, and type p.

The Vim command cheat sheet

Tags:

Vim

Editing