Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to paste multiple lines in Vim?

Tags:

vim

QUESTION:
I am deleting/copying every other line with :g/^/+d However, when I try pasting all of those lines only the last line gets pasted. How do I paste every single line that I deleted/copied?

RESOLVED:
Thanks everyone! With your help I was able to finish my video (I work on a Youtube channel called Vim Girl where I make guided Vim Golf challenges.) Here's the link if you're interested: https://youtu.be/S9o5bHUAbP0

like image 792
seemcat Avatar asked Dec 18 '22 06:12

seemcat


2 Answers

You can use a capital register to append to a register. First clear a register by either doing :let @a='' or qaq. Then execute your command.

:g/^/+d A

Now your results are in the "a register. e.g. "ap.

Assuming you are pasting this all at the bottom this could look like the following all together:

:let @a=''
:g/^/+d A
:$pu a

Note: this is equivalent to :g/^/+m$

For more help see:

:h :let-@
:h :d
:h quote_alpha
like image 145
Peter Rincker Avatar answered Jan 14 '23 17:01

Peter Rincker


you could write a macro to append everything to the end:

qdddGp<ctrl + o>jq

then run it as many times (20, e.g.) as you need using:

20@d
like image 28
acushner Avatar answered Jan 14 '23 17:01

acushner