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
Is there an easier way (fewer keystrokes)?
You can type
V to select the line, then
p to replace it.
Another way to do this would be
"_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!
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, but not delete. The
"9 registers store the last 9 deletes/cuts you've done. So:
yy, you could replace with
cc, you could replace with
:help "0 for more in-depth info.
Suppose you want to replace line 1 by 3 than you could do
This effectively moves line 1 to line 3, and removes line 2 (i.e. the old line 3)