VIM用粘贴缓冲区的内容替换单词吗? [英] VIM Replace word with contents of paste buffer?

查看:97
本文介绍了VIM用粘贴缓冲区的内容替换单词吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在文件中进行大量单词替换,并希望使用vi命令而不是像:%s /// g 。我知道这是在当前光标位置替换单词的典型方法: cw< text>< esc> ,但是有一种方法可以对内容进行替换

I need to do a bunch of word replacements in a file and want to do it with a vi command, not an EX command such as :%s///g. I know that this is the typical way one replaces the word at the current cursor position: cw<text><esc> but is there a way to do this with the contents of the unnamed register as the replacement text and without overwriting the register?

推荐答案

我在想粘贴?您的意思是未命名的(yank / put / change / delete / substitute)寄存器,对吗? (因为那是被change命令覆盖的那个。)

I'm thinking by "paste" you mean the unnamed (yank/put/change/delete/substitute) register, right? (Since that's the one that'd get overwritten by the change command.)

通常通过键入 来指定寄存器。寄存器的名称(单个字符),例如 ay 然后是 ap ,以拉入寄存器 a ,然后将寄存器 a 的内容放入。更改命令也是如此。在这种情况下,如果您不希望将使用change命令删除的文本放在任何地方,则可以使用黑洞寄存器< _ _ cw 。然后,在插入模式下,您可以先按ctrl-R,再按所需的寄存器(可能是 )放入该寄存器的内容。

Registers are generally specified by typing " then the name (single character) of the register, like "ay then "ap to yank into register a, then put the contents of register a. Same goes for a change command. In this case, if you don't want the text you remove with the change command to go anywhere, you can use the black hole register "_: "_cw. Then once in insert mode, you can hit ctrl-R followed by the register you want (probably ") to put in the contents of that register.


  • " * -选择寄存器(中间按钮粘贴)

  • + -剪贴板寄存器(也可以通过终端通过ctrl-shift-v访问)

  • ;" -vim的默认(未命名)yank / put / change / delete / substitute寄存器。

  • "* - selection register (middle-button paste)
  • "+ - clipboard register (probably also accessible with ctrl-shift-v via the terminal)
  • "" - vim's default (unnamed) yank/put/change/delete/substitute register.

简短答案: _ cw ^ R

编辑:正如其他人所建议的那样,您当然可以使用其他寄存器来存储请求(或其他方式) ),将您的文本保存到默认寄存器中。不过,您不一定总是首先想到这一点,因此执行单个更改命令而不用浪费它是很好的。尽管还没有完全消失。有编号的寄存器 0 9

as others are suggesting, you can of course use a different register for the yank (or whatever) that got your text into the default register. You don't always think of that first, though, so it's nice to do a single change command without blowing it away. Though it's not totally blown away. There are the numbered registers "0 through "9:


Vim用yank和delete命令中的文本填充这些寄存器。

Vim fills these registers with text from yank and delete commands.

编号寄存器0包含最新yank命令中的文本,除非该命令指定了另一个寄存器[ x]。

Numbered register 0 contains the text from the most recent yank command, unless the command specified another register with ["x].

编号寄存器1包含由最近的delete或change命令删除的文本,除非该命令指定了另一个寄存器或文本少于一行(小然后使用删除寄存器)。使用以下移动命令对delete运算符进行例外处理:` / n N {} 。然后总是使用寄存器 1(这是Vi兼容的)。如果删除在一行内,也将使用-寄存器。

Numbered register 1 contains the text deleted by the most recent delete or change command, unless the command specified another register or the text is less than one line (the small delete register is used then). An exception is made for the delete operator with these movement commands: %, (, ), `, /, ?, n, N, { and }. Register "1 is always used then (this is Vi compatible). The "- register is used as well if the delete is within a line.

每次连续删除或更改时,Vim会将寄存器1的先前内容移入寄存器2、2到3 ,依此类推,丢失了寄存器9的先前
内容。

With each successive deletion or change, Vim shifts the previous contents of register 1 into register 2, 2 into 3, and so forth, losing the previous contents of register 9.

这篇关于VIM用粘贴缓冲区的内容替换单词吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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