在粘贴选定的文本时,vim如何保持寄存器的内容? [英] How can vim keep the content of register when pasting over selected text?

查看:96
本文介绍了在粘贴选定的文本时,vim如何保持寄存器的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一行文本已被 yy 取消.现在,我想使用此文本替换其他几个地方的行.麻烦在于,当我选择要替换的行 V 并粘贴 p 时,所选文本将自动被选中!那就是我所不想要的.

I have a line of text I have yanked yy. Now I want to use this text to replace lines at several other places. The trouble is that when I select V the line to be replaced, and paste p, the text that was selected is automatically yanked! That's what I don't want.

更改寄存器不起作用,因为粘贴和拉动都是通过新选择的寄存器完成的.

Changing the register does not work, because both the paste and the yank are done with the newly selected register.

在粘贴选定文本时保留寄存器内容的命令是什么?

What is the command to keep the content of the register when pasting over selected text?

推荐答案

每次您对某些内容进行 p 时,它都会进入默认寄存器.

Each time you p over something it goes into the default register.

要变通解决此功能,您必须先使用"__ ,"黑洞寄存器,这是我在<代码>〜/.vimrc :

To work around this feature you have to use "_, "the black hole register", before you p. Here is a custom mapping I have in my ~/.vimrc:

vnoremap <leader>p "_dP

它将删除所选内容并将其放入黑洞寄存器中(这意味着所选文本将永远消失),并将默认寄存器的内容替换为先前选择的文本,同时保留默认寄存器不变.

It deletes the selected content and drops it in the black hole register (this means that the selected text disappears forever) and puts the content of the default register in place of the previously selected text while leaving the default register intact.

当我需要在一些地方用另一个looooooong url替换loooooooong url且制作 s//太麻烦时,我经常使用它.

I use it often when I need to replace a loooooooong url in a few places with another looooooong url and crafting a s// would be too cumbersome.

这篇关于在粘贴选定的文本时,vim如何保持寄存器的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆