Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I cc or dd to copy a line into my paste buffer. Then I go to a new location.

I want to replace a line that I see. So I type p Down dd.

Is there an easier way (fewer keystrokes)?

share|improve this question
Hmm, for one off edits, that's how I usually do it. I'd be interested in any shorter way as well. – jw013 Jul 14 '12 at 18:38
You can type V to select the line, then p to replace it. – angus Jul 14 '12 at 18:45
@angus, turn that comment into an answer! It's a good answer. – Jander Jul 14 '12 at 19:26
up vote 8 down vote accepted

You can type V to select the line, then p to replace it.

share|improve this answer
I think this is the only anwer I've seen that actually has less keystrokes than dd, move, pjdd. – jw013 Jul 15 '12 at 4:15

Another way to do this would be "_ddp

"_dd deletes the current line to the null-buffer. This doesn't over write what you had just copied, which I have found helpful a lot of times! The p pastes the line you had copied earlier.

Might not be shorter in terms of keystrokes, but knowing this is an option can be very helpful!

share|improve this answer

Angus and Thor have the short answers covered, so here's some bonus exploration.

If for some reason you want to delete before pasting, you can take advantage of the numbered registers. The "0 register contains the text yanked by the last y or Y, but not delete. The "1 through "9 registers store the last 9 deletes/cuts you've done. So:

  • If you yanked with yy, you could replace with dd"0P.
  • If you cut with dd or cc, you could replace with dd"2P. (Not dd"1P because the dd fills "1.)

Try :help "0 for more in-depth info.

share|improve this answer

Suppose you want to replace line 1 by 3 than you could do :1m3|2d

This effectively moves line 1 to line 3, and removes line 2 (i.e. the old line 3)

share|improve this answer

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.