tags:

views:

87

answers:

6

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

A: 

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
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
A: 

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.
A: 

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
A: 

Go on the line you wish to change, and execute

V"kp
Luc Hermitte
The only downside to this one is that in gvim it'd be likely to alter the contents of the system clipboard.
Benj
Just fix v_p then -> http://stackoverflow.com/questions/290465/vim-how-to-paste-over-without-overwriting-register/290723#290723
Luc Hermitte
Haha, yes I suppose that's a possibility.
Benj
A: 

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
A: 

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