粘贴多次

发布于 2024-12-01 03:58:03 字数 131 浏览 2 评论 0原文

用剪贴板的内容替换多行的最佳方法是什么?

我遇到的问题是,当我猛拉一行并将其粘贴到另一行上时,“猛拉”将替换为我刚刚替换的行。现在,如果我想用同一行替换另一行,我必须返回并再次拉动它。

必须有更好的方法来做到这一点。

What is the best way replace multiple lines with the contents of the clipboard?

The problem I'm having is when I yank a line and paste it over another line the "yank" is replaced with the line I just replace. Now, if I want to replace another line with the same line I have to go back up and yank it again.

There's got to be a better way to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(9

粉红×色少女 2024-12-08 03:58:03

我的 .vimrc 中有这个:(

xnoremap p pgvy

注意:这仅适用于默认寄存器,但此映射很容易记住)。编写更详细的版本是可能的。

另外,您可以按 P (Shift+p) 而不是 p 来粘贴所选内容,而不覆盖所选内容剪贴板。

I have this in my .vimrc:

xnoremap p pgvy

(note: this will work only with the default register, but this mapping is easy to remember). Writing a more elaborate version would be possible.

Also, you can press P (Shift+p) instead of p to paste over the selection without overwriting the clipboard.

小红帽 2024-12-08 03:58:03

"0 应该包含您复制的内容。输入起来有点乏味,但是 "0p 应该可以完成您想要的操作。

或者,不要预先选择并替换旧行。如果您通过搜索找到这些行,只需一遍又一遍地点击 n. (在初始 p 之后),然后当它们全部粘贴后,执行 ndd 后跟任意数量的 n.

迁移到 Vim 时,我需要做出的最大的心理转变是弄清楚如何按顺序应用组编辑。即,我不会在一行上进行一堆编辑,然后在另一行上进行一堆相同的编辑,而是对一堆行进行第一次编辑(使用 . 效果很好) ,然后对一堆行进行第二次编辑,等等。或者,使用宏可能会有所帮助,因为它们非常棒,但有时要正确处理“复杂”更改会更加乏味。

"0 should have the contents of your yank. It's a bit more tedious to type, but "0p should do what you want.

Alternatively, don't select-and-replace the old lines up front. If you find those lines with a search, just hit n. over and over (after an initial p), then when they're all pasted, do ndd followed by as many n.s as necessary.

The biggest mental switch I've needed to make when moving to Vim is to figure out how to apply group edits sequentially. I.e. rather than doing a bunch of edits on a line and then doing a bunch of the same edits on another line, I'll do the first edit on a bunch of lines (using . to great effect), then the second edit on a bunch of lines, etc. Alternatively, the use of macros may help as they are fantastic, but sometimes a little more tedious to get working correctly with "complex" changes.

嘿哥们儿 2024-12-08 03:58:03

我经常使用另一个注册表,将您需要的行复制到某个名为的注册表“ay”,然后从那里粘贴“ap

I often use another registry, copy the line you need to some named registry "ay and then paste from there "ap

西瓜 2024-12-08 03:58:03

当您在 Vim 中粘贴所选内容时,它将用所选内容替换默认寄存器。如果粘贴所选内容会清除剪贴板寄存器的内容,那么很可能您的 .vimrc 中有以下行。

set clipboard=unnamed

一个选项是删除它并使用显式剪贴板寄存器 "+

另一个选项是例如,在第一次粘贴后,使用任何其他显式命名的寄存器 (az) 将行拉回到 "c 中,然后使用 "cp 从那里粘贴。出去。

When you paste over a selection in Vim it will replace the default register with the contents of the selection. If pasting over a selection is wiping out the contents of the clipboard register then very likely you have the following line in your .vimrc

set clipboard=unnamed

One option is to remove that and use the explicit clipboard register "+

Another option is to use any of the other explicitly named registers (a-z). After the first paste yank the line back into "c for example and then use "cp to paste from there on out.

梦里寻她 2024-12-08 03:58:03

与使用复制/粘贴不同,通常最好使用文本对象命令(例如 ciw)来更改内部单词。此方法的优点是可以使用 . 重复命令轻松重复。

  1. yiw 复制内部单词(复制光标下的单词,说“第一个”)。
  2. ...将光标移动到另一个单词(例如“第二个”)。
  3. ciw0 更改“第二”,将其替换为“第一”(即 Ctrl-R)。
  4. ...将光标移动到另一个单词(例如“第三”)。
  5. . 更改“third”,将其替换为“first”。

Instead of using copy/paste, it is often better to use a text object command such as ciw to change the inner word. This method has the advantage of being easily repeatable using the . repeat command.

  1. yiw Yank inner word (copy word under cursor, say "first").
  2. ... Move the cursor to another word (say "second").
  3. ciw<C-r>0 Change "second", replacing it with "first" ( is Ctrl-R).
  4. ... Move the cursor to another word (say "third").
  5. . Change "third", replacing it with "first".
嘿看小鸭子会跑 2024-12-08 03:58:03

使用np,其中n是您想要粘贴行的次数,例如3p将粘贴3行。

use np where n is the number of how much time you want to paste the lines eg 3p will paste 3 lines.

海拔太高太耀眼 2024-12-08 03:58:03

使用 P 而不是 p

p 将从未命名寄存器 (") 粘贴,并将其内容替换为已删除的文本。

P 将从未命名寄存器 (") 继续粘贴,而不将其内容替换为已删除的文本 。已删除的文字。

Use P instead of p.

p will paste from the unnamed register (") and replace its contents with the deleted text.

P will keep pasting from the unnamed register (") without replacing its contents with the deleted text.

像极了他 2024-12-08 03:58:03

添加以下键映射,按 Ctrlp 进行粘贴。

" Paste Register 0  
map <C-p> "0p

Add below key mapping, hit Ctrlp to paste.

" Paste Register 0  
map <C-p> "0p
流年里的时光 2024-12-08 03:58:03

当您使用 yank 时,它会复制到 "0 寄存器中,如 :reg 所示
被复制的东西进入默认寄存器

我们可以每次粘贴“0寄存器,注意默认寄存器仍然会有最后粘贴的东西。

xnoremap p "0p

When you use yank, it copies into the the "0 register, as can be seen with :reg
The thing being copied over goes to the default register

We can paste "0 register each time, note the default register will still have the last thing pasted over.

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