Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

For example

alt text

How can I yank and paste Line 4 only to Line 12 without having to move the cursor to Line 4?

alt text

share|improve this question
I answered your question base on the fact that "yank me!" is on line 4. In your 2nd screenshot, it appears on line 5. –  Louis Salin Aug 26 '10 at 16:29
Thanks @Louis for the answer. I have updated the screenshot. –  Lazer Aug 26 '10 at 18:23

5 Answers 5

up vote 38 down vote accepted

If the cursor is already on line 12, then a simple


does it for me.

share|improve this answer
Nice! Is there an equivalent for x? When I try :4x I get E140: Use ! to write partial buffer. Thanks! –  dotancohen Jun 28 '12 at 17:01
I have to say this is amazing :D –  nXqd Aug 8 '12 at 7:11
@dotancohen :4d –  n.st Oct 7 '13 at 0:30

Try this:

share|improve this answer



You can use an argument of 0 to paste to line 1. This will also work with ranges:

:m,n co k

will copy lines m through n to line k+1. In addition it doesn't matter where you are in the buffer. The move command, m, works similarly.

share|improve this answer

How about this: Cursor is on line 11, you're in "vi" mode.


You can apparently also do it with a pattern:


You could use "mo" (move) instead of "co" (copy) to just move the line, instead of yank and put.

share|improve this answer

This should do it:

share|improve this answer
No, that yanks line numbers 4 to 12. –  Lazer Aug 26 '10 at 16:00
I meant copy and paste line 4, to line 12. –  Lazer Aug 26 '10 at 16:01
Edited. Is this what you wanted? –  Umang Aug 26 '10 at 16:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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