开发者

how to replace a current line with what in a buffer using vi

Say i have line stored in buffer k. how do I replace some line with the content of the buffer开发者_Go百科?


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

so "xPdd


Go on the line you wish to change, and execute

V"kp


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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜