How to replace the current line with something in the buffer using vi

Let's say my string is saved in buffer k. How to replace some string with the contents of the buffer?

+4
source share
6 answers

As others have said, the general answer is to use dd "kP. I would like to add that you can use: g, so if you want to replace all the lines that match 'foo' with the contents 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.

+4
source

go to any point to be replaced. Execute buffer P (put above). Use dd to delete the current line.

so "xPdd

+6
source

Scroll to the line you want to change and do

V"kp 
+5
source

The best way I can think in place is

"ayy (this is yanks / copy string to" buffer

then

dd (delete line to standard buffer)

then

"aP that inserts the buffer" a before the current line

+3
source

The quote key "is what you need. It makes your yank / put register specific. So you have something in register k, and you would like to replace the current line with it, which you would write:

 ^c$<esc>"kp 
+1
source

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

0
source

All Articles