如何使用 vi 将当前行替换为缓冲区中的内容
假设我有行存储在缓冲区 k 中。如何用缓冲区的内容替换某些行?
Say i have line stored in buffer k. how do I replace some line with the content of the buffer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
走到线路上的任何地方进行更换。执行缓冲区 P(放在上面)。使用 dd 删除当前行。
所以“xPdd
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
正如其他人所说,总体答案是使用 dd"kP。我想补充一点,您可能想要使用 :g,这样如果您想用寄存器 k 的内容替换所有与 'foo' 匹配的行,你可以这样做:
请注意,如果缓冲区的第一行与模式匹配,则使用 p 而不是 P 会导致一些问题。
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:
Note that using p instead of P will cause some problems if the first line of your buffer matches the pattern.
我能当场想到的最好方法是
“ayy(这会将行拉入/复制到“a缓冲区
,然后
dd(将行删除到标准缓冲区)”
然后
“在当前行之前插入缓冲区的aP”
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
引号键 " 就是您所需要的。这使得您的 yank/put 寄存器变得特定。因此您在寄存器 k 中有一些内容,并且您想用它替换当前行,您可以输入:
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:
您可以使用 ctrl-v 并选择要复制的内容,然后按“y”来“猛拉”它。然后按 ctrl-v 或 shift-v 选择要替换的“某些行”,然后按“p”进行粘贴。
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.