如何在 Vim 中重复任何命令,例如“Cx z”在 emacs 中?
在Vim中,有没有办法重复最后一个命令,无论它是否是编辑,并且没有先见之明先录制宏?
例如,假设我输入 :bn
,并想再输入一次(这是错误的文件)。按 .
显然不起作用。或者也许我正在执行 gE
并想重复该操作(只需击键一次,因为显然 gE
打字有点痛苦)。
也许有一些插件?类似于这个问题。
(更酷的是追溯地将多个命令绑定到宏,这样就可以输入 5qa@a 或其他内容来重复最后 5 个命令...)
In Vim, is there any way to repeat the last command regardless of whether it was an edit or not, and without having the foresight to first record a macro?
E.g. say I type :bn
, and want to do it again (it was the wrong file). Pressing .
obviously doesn't do it. Or maybe I'm doing gE
and want to repeat that (with one keystroke since clearly gE
is kinda painful to type).
Perhaps there are some plugins? Similar to this question.
(Even cooler would be to retroactively bind a number of commands to a macro, so one could type 5qa@a
or something to repeat the last 5 commands...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要重复命令行命令,请尝试
@:
,要重复正常/插入模式命令,请尝试.
,如果需要,请将以下映射添加到您的 .vimrc快捷方式相同:-
:noremap; @:
- 这会将 Ctrl+P 映射到上一个命令行命令。您可以映射任何其他组合。To repeat a command-line command, try
@:
, To repeat a normal/insert-mode command, try.
,Add below mapping to your .vimrc if you want to shortcut the same:-
:noremap <C-P> @:<CR>
- This will map Ctrl+P to previous command-line command. You can map any other combo.:help Repeating
将提供典型的重复命令(如 .、@: 等)。你可以尝试repeat.vim。这可能会让您更接近您正在寻找的东西。:help repeating
will provide the typical repeat commands (like ., @:, etc.). You could try repeat.vim. That may get you closer to what you are looking for.对于运动命令,Vim 中没有内置机制。 “查找”和“到”命令 (
f
/F
/t
/T
) 具有;
和,
重复和反转。有几个插件可以扩展这些绑定以重复其他运动命令:http://www.vim。 org/scripts/script.php?script_id=2174
http://www.vim.org /scripts/script.php?script_id=3665
后者应该支持使用
;
重复gE
For motion commands there is no mechanism built into Vim. The Find and To commands (
f
/F
/t
/T
) have;
and,
to repeat and reverse. There are a couple of plugins which extend those bindings to repeat other motion commands:http://www.vim.org/scripts/script.php?script_id=2174
http://www.vim.org/scripts/script.php?script_id=3665
The later should support repeating
gE
using;
您可以只使用“。”
例子:
您的文件中有 10 个位置有“abc”,您想将其中的 5 个位置替换为“def”。
第 1 步:通过键入命令“/abc”查找 abc 第一次出现的位置
步骤2:当光标位于“abc”上时,用命令“cw”替换abc,即可取出单词“abc”
第 3 步:输入“def”作为替换,然后按 Enter 键进入命令模式
第 4 步:要重复此操作,只需键入命令“n”即可转到下一个出现的 abc ,然后键入命令“.”。 该命令会记住您上次将“abc”替换为“def”,并将在此处执行相同的操作。
You can just use "."
Example:
You have "abc" at 10 places in your file and you want to replace it with "def" at 5 places of it.
Step 1: Find first occurance of abc by typing command "/abc"
Step 2: Once cursor is on "abc", Replace abc by command "cw" to take out word "abc"
Step 3: Type in "def" as replacement and press enter to go to command mode
Step 4: To repeat this action just type command "n" to go to next occurrence of abc and type command "." . The command remembers that you replaced "abc" with "def" last time and will perform the same here.
为了更方便,您可以将
@:
映射到某个键:然后更容易将其与重复一起使用。
You can map
@:
to some key for more convenience:and then it's easier to use it with repeats.