如何重复 Vim 中的最后 n 个更改?
执行 .
会重复上次更改。执行 2.
会重复上次更改两次。
但想象一下我想在最后一个更改之前重复更改。我如何在 Vim 中做到这一点?
Doing .
repeats the last change. Doing 2.
repeats the last change two times.
But imagine I want to repeat the change before the last one. How do I do it in Vim?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 Fredrick Phil 的回答,这里有一个示例:
录制宏
下面演示了如何录制宏以删除带引号的字符串中的所有内容(包括带引号的字符串)并存储在寄存器
d
中。删除字符串的命令是da"
。因此,要将这个命令存储在宏寄存器 d 中,我们可以简单地执行以下操作:注意它以 q 开头和结尾。第二个字符是寄存器,在此case
d
表示删除。但我们可以给它任何字母或数字,剩下的字符da"
是我们的命令。使用我们的宏
现在我们的宏已被录制,我们可以通过使用 @ 符号后跟寄存器来调用它:
重复上一个宏命令
要使用最近调用的宏命令再次:
无关信息:
在本例中,我们使用了
da"
,它代表删除带引号的字符串
。(如果您想删除所有内容在
引用的字符串内,但不是引号本身,您可以使用di"
代替。)。Based on Fredrick Phil's answer, here is an example:
Recording your macro
The following shows how to record a macro to delete everything in and including a quoted string and store in register
d
. The command to delete a string isda"
. So to store this command in macro register d we can simply do this:Notice it starts and ends with a q. The second character is the register, in this case
d
for delete. But we could have given it any letter or number. The remaining charactersda"
is our command.Using our macro
Now that our macro is recorded we can invoke it by using the @ symbol followed by the register:
Repeating the last macro command
To use the most recently invoked macro command again:
Unrelated info:
In this example, we used
da"
which stands fordelete a quoted string
. (If you instead wanted to delete everythinginside
the quoted string, but not the quotation marks themselves you can instead usedi"
instead.).记录您的“编辑”
是的!你可以在 vim 中做到这一点!
Record Your "Edits"
yes! you can do this in vim! ????
One of Vim's most useful features is its ability to record what you type for later playback. This is most useful for repeated jobs that cannot easily be done with .
To start recording
To stop recording
To playback your keystrokes/recording
References
您不认为可以,请参阅
:help 。
但是,您可以做的是为您的编辑录制宏,您有很多寄存器可供选择{0-9a- zA-Z"}
(大写以追加)。然后使用例如
@u
来编辑 1,使用@t
来编辑 2,依此类推。Best of VIM Tips 有关录制的精彩提示,
请查看以下内容以获取更多重复提示:
Don't think you can, see
:help .
However, what you can do is to record a macro for your edits, you have a lot of registers to choose from{0-9a-zA-Z"}
(uppercase to append).Then use e.g.
@u
for edit 1,@t
for edit 2 and so on.Great tips about recording from Best of VIM Tips
Have a look at these for more hints for repeating:
我编写了RepeatLast.vim 插件来满足这个确切的要求。它提供
5\.
键绑定来重复最后 5 个更改(包括移动),并提供2\D
来删除/忘记最后 2 个操作。它的工作原理是始终启用宏录制,这可能并不适合所有人。但如果您能接受这一点,它就适用于 99% 的用例。
最新版本: https://github.com/joeytwiddle/RepeatLast.vim (请反馈!)
从长远来看,训练您的 q 肌肉来先发制人地记录宏可能是更好的方法。 ;-)
I wrote the RepeatLast.vim plugin to address this exact requirement. It provides a
5\.
key binding to repeat the last 5 changes (including movements) and2\D
to drop/forget the last 2 actions.It works by enabling macro recording all the time, which may not be desirable for everyone. But if you can live with that, it works in 99% of use cases.
Latest version: https://github.com/joeytwiddle/RepeatLast.vim (Please feedback!)
Training your
q
muscle to pre-emptively record macros might be a better approach in the long term. ;-)