Jiho Noh
Jiho Noh

Reputation: 489

In vi, select lines and copy/paste from different lines

I know there must be a way to do this. It's somewhat difficult to search this kind of tricks.

What I want is to copy lines from xx to yy and paste them where my cursor is. I know how to yank and paste, but I want to do this without moving my cursor to the lines where I want to copy and get back to the line where I want to paste.

Copy and paste without navigating lines is what I want.

Upvotes: 1

Views: 671

Answers (2)

Nurjan
Nurjan

Reputation: 6053

You can do it this way:

:5,6copyN, where N is the line under which the lines will copied to.

Note that, the line N must exist in your file, i.e. your cursor should be there at least once before you want to do copy/paste.

Upvotes: 1

Marcelo
Marcelo

Reputation: 4282

You can do this using the command-line mode. To yank line 2 to 20

:2,20y

then just hit p on the current line.

Upvotes: 1

Related Questions