5

Say i have line stored in buffer k. how do I replace some line with the content of the buffer?

vehomzzz
  • 42,832
  • 72
  • 186
  • 216

6 Answers6

7

go anywhere on the line to be replaced. Execute a buffer P (Put above). Use dd to delete the current line.

so "xPdd

Asklepius M.D.
  • 283
  • 2
  • 5
5

Go on the line you wish to change, and execute

V"kp
Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
4

As others have said, the overall answer is to use dd"kP. I'd like to add that you might want to use :g, so that if you want to replace all lines that match 'foo' with the content of register k, you can do:

:g/foo/normal dd"kP

Note that using p instead of P will cause some problems if the first line of your buffer matches the pattern.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
3

best way i can think on the spot is

"ayy (this yanks / copies the line to the "a buffer

then

dd (delete the line to the standard buffer)

then

"aP which inserts buffer"a before the current line

PurplePilot
  • 6,652
  • 7
  • 36
  • 42
1

The quote key " is what you need. That makes your yank/put register specific. So you have something in register k and you wanted to replace the current line with it you'd type:

^c$<esc>"kp
Benj
  • 31,668
  • 17
  • 78
  • 127
0

You can use ctrl-v and select what you want to copy and press "y" to "yank" it. Then ctrl-v or shift-v to select the "some lines" that you want to replace and press "p" to paste it.

Randall
  • 19
  • 1
  • I not copying anything on the fly. I am pre-storing certain lines that I will use to replace some line in the code. – vehomzzz Dec 09 '09 at 14:54