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

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

问题描述

我需要在文件中进行大量单词替换,并希望使用 vi 命令而不是诸如 :%s///g 之类的 EX 命令.

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.

我知道这是替换当前光标位置的单词的典型方式:cw 但是有没有办法用未命名的内容来做到这一点?注册为替换文本而不覆盖注册?

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?

推荐答案

I'm thinking by paste";你的意思是未命名的(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的内容.更改命令也是如此.在这种情况下,如果您不希望使用更改命令删除的文本去任何地方,则可以使用黑洞寄存器 "_: "_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"

正如其他人所建议的那样,您当然可以为将文本放入默认寄存器的 yank(或其他任何内容)使用不同的寄存器.但是,您并不总是首先想到这一点,因此执行单个更改命令而不将其吹散是很好的.虽然它并没有完全被吹走.有编号的寄存器 "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 包含由最近的删除或更改命令删除的文本,除非该命令指定了另一个寄存器或文本少于一行(然后使用小删除寄存器).删除操作符的例外是这些移动命令:%, (, ), `, /?nN{}.然后总是使用寄存器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.

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

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