Vim: .(句点)重复上一条命令。如何重复上上条命令?

3
Vim: . 重复上一个命令。重复上上个命令的命令是什么?
例如:
我使用命令dd删除了一行,然后使用命令x删除了一个字符。 x是上一个命令,dd是上上个命令。
可以使用.重复上一个命令x。 但是,我想使用类似于.的东西来重复dd命令。

请做一个例子。 - Kent
@Kent:给出示例 - Sagar Jain
1
你知道vi.stackexchange.com吗?(我很愿意回答你的问题,而不是给你一个链接,但是我不知道有这样的功能。) - DevSolar
@DevSolar:我不知道那个网站。谢谢。 - Sagar Jain
1个回答

5

简短回答:Vim本身没有这样的功能。

然而,以下建议应该有助于您更好地使用Vim:

  • For your specific example, instead of typing dd to delete the line you could use the :d Ex (command-line) delete command. This can be later repeated using @: without effecting the . command.

  • If you're doing something more complicated than deleting a line with dd, you could record it as a macro using q{registername} (where {registername} denotes any unused non-special register name in the range a-z, e.g., qa). After having executed the macro using @{registername} (e.g., @a) it can be repeated by simply running @@.

  • If you'd like to learn more about other ways of repeating commands, I'd suggest reading repeat.txt from Vim's built-in manual:

    :h repeat.txt
    

    This file lists other ways of repeating commands such as using Ex commands and recording / executing macros.

重复替换命令

最近一次的:substitute命令可以使用:s:&进行重复。这将使用相同的搜索模式和替换字符串,但不使用相同的标志或范围(必须提供它们)。甚至更短的重复命令的同义词是&。有关更多信息,请参见:help :substitute


@SagarJain 没错。我本意是用{registername}来表示从az之间的任何有效寄存器名称。我会编辑我的回答,使其更清晰明了。 - Anthony Geoghegan
1
@SagarJain 我编辑了我的答案,增加了一个关于重复替换命令的额外部分。 - Anthony Geoghegan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接