Say i have line stored in buffer k. how do I replace some line with the content of the buffer?
6 Answers
go anywhere on the line to be replaced. Execute a buffer P (Put above). Use dd to delete the current line.
so "xPdd
- 283
- 2
- 5
Go on the line you wish to change, and execute
V"kp
- 31,979
- 7
- 69
- 83
-
The only downside to this one is that in gvim it'd be likely to alter the contents of the system clipboard. – Benj Dec 09 '09 at 15:08
-
Just fix v_p then -> http://stackoverflow.com/questions/290465/vim-how-to-paste-over-without-overwriting-register/290723#290723 – Luc Hermitte Dec 09 '09 at 15:44
-
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.
- 204,365
- 48
- 270
- 300
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
- 6,652
- 7
- 36
- 42
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
- 31,668
- 17
- 78
- 127
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.
- 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