选择当前单词的多个实例并更改它们的vim方式是什么? [英] What's the vim way to select multiple instances of current word and change them?

查看:29
本文介绍了选择当前单词的多个实例并更改它们的vim方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何熟悉 Sublime Text 的多光标功能的人都会认识到执行以下操作的模式:多次按下热键以选择光标下单词的多个实例,并为每个实例自动创建一个新光标;然后同时编辑每个实例,例如用另一个词或任何你想要的词替换当前词.

Anyone familiar with Sublime Text's multiple cursor feature will recognize the pattern of doing the following: press a hotkey multiple times to select multiple instances of the word under the cursor and automatically create a new cursor for each of those instances; then edit each instance simultaneously, e.g. by replacing the current word with another word or whatever you want.

多游标功能可通过 插件 用于 vim.在使用该插件之前,我想(作为一个新的 vim 用户)检查是否有更原生的类似 vim 的方式来实现相同的任务.

The multiple cursors feature is available for vim via plugin. Before using that plugin, I want (as a new vim user), to check whether there is a more natively vim-like way to achieve the same task.

例如,我知道我可以使用 :s 命令进行搜索和替换(根据说明 此处),但这需要我 (1) 输入要替换的单词(或使用 <C-r><C-a>快捷方式),而不是简单地使用当前单词和(2)定义一个范围.也许这是执行此操作的原生 vim 方式,也许(可能!)还有另一种我不知道的方式.

For instance, I know I could use the :s command to do a search and replace (per instructions here), but that requires me to (1) type in the word I want to replace (or use the <C-r><C-a> shortcut to do so), as opposed to simply using the current word and (2) define a range. Perhaps this is the native vim way to do it, perhaps (likely!) there's another way I don't know.

那么原生vim方式是什么?

So what is the native vim way?

推荐答案

我使用 *gn. 来制作变化.

I use the *, gn, and the . to make changes.

  • *选择当前单词(用N返回)
  • gn 动作改变单词.例如cgnfoo
  • 通过.命令重复
  • Select current word with * (go back with N)
  • Change word with gn motion. e.g. cgnfoo<esc>
  • Repeat via . command

注意:如果您有很多更改,那么使用替换命令可能会更好.

Note: If you have many changes then using a substitution command would probably be better.

有一个关于 gn 动作的很好的 Vimcasts 插曲:使用 gn 操作搜索匹配.

There is a nice Vimcasts episode about the gn motion: Operating on search matches using gn.

有关更多帮助,请参阅:

For more help see:

:h *
:h gn
:h .

这篇关于选择当前单词的多个实例并更改它们的vim方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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