如何用缓冲区中的字符串替换引号中的字符串?
我正在执行以下操作来复制引号内的一些文本并将其粘贴到不同的位置(也在引号内):
di"
go-to-buffer-for-copy
copy-string (ex. yi")
then-go-to-prev-buffer
paste-to-string (p)
但我想以更简单的方式执行此操作,如下所示:
yi"
go-to-buffer-for-paste
replace-inner-quotes-to-yanked-text
I'm doing the following to copy some text inside quotes and paste it in a different place (inside quotes as well):
di"
go-to-buffer-for-copy
copy-string (ex. yi")
then-go-to-prev-buffer
paste-to-string (p)
But I want to do it in a simpler way, like this:
yi"
go-to-buffer-for-paste
replace-inner-quotes-to-yanked-text
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于“replace-inner-quotes-to-yanked-text”,您可以使用
vi"p
。For "replace-inner-quotes-to-yanked-text" you can use
vi"p
.(将我的评论拉到自己的答案中)
假设您将
vim
与系统剪贴板一起使用,您可以执行以下操作:"+yi"
将引号内的文本复制到您的系统剪贴板ci"
将引号内的内容替换为剪贴板的内容一个好处是,如果您想要将原始文本放在多个位置,您可以将光标放在下一个位置并按
vi"p,由兰迪·莫里斯 (Randy Morris) 提出,可以使用,但它可以替代。默认寄存器的内容和选择不会在“重做”命令中捕获,只会捕获粘贴。
您仍然可以使用
"0
寄存器来访问原始文本,但我还没有找到可以在引号内更改并以重做维护的方式粘贴的命令。(pulling my comment into its own answer)
Assuming you use
vim
with system clipboard, you could do the following:"+yi"
to copy the text inside quotes to your system clipboardci"<Ctrl-V><Esc>
replaces what's inside the quotes with the content of your clipboardOne benefit is that if you want to put the original text in multiple places, you can place your cursor in the next position and press
.
.vi"p
, proposed by Randy Morris, works but it replaces the content of your default register and the selection won't be captured in the "do again" command, only the paste.You could still use the
"0
register to access your original text but I haven't found a command that would change inside the quotes and paste in a way that redo maintains.这种技术使您能够脱离插入模式,并且不需要将未命名的剪贴板映射到系统剪贴板:
yi"
(在引号?'
内拉入,然后是第一个)目标引号当前内容的几个字母(向后搜索)p
(粘贴)dt"
(删除引号中预先存在的内容This technique enables you to stay out of insert mode and doesn't require mapping the unnamed clipboard to the system clipboard:
yi"
(yank inside the quotes?'
followed by first few letters of current contents of target quotes (search back)p
(paste)dt"
(delete the pre-existing content that was in the quotes