如何用缓冲区中的字符串替换引号中的字符串?

发布于 2024-10-08 07:54:07 字数 282 浏览 0 评论 0原文

我正在执行以下操作来复制引号内的一些文本并将其粘贴到不同的位置(也在引号内):

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泛滥成性 2024-10-15 07:54:07

对于“replace-inner-quotes-to-yanked-text”,您可以使用 vi"p

For "replace-inner-quotes-to-yanked-text" you can use vi"p.

烙印 2024-10-15 07:54:07

(将我的评论拉到自己的答案中)

假设您将 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 clipboard
  • position your cursor inside the quotes where you want to put that text
  • ci"<Ctrl-V><Esc> replaces what's inside the quotes with the content of your clipboard

One 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.

唐婉 2024-10-15 07:54:07

这种技术使您能够脱离插入模式,并且不需要将未命名的剪贴板映射到系统剪贴板:

  • 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文