问题描述
在vim中,在我的.vimrc中,如何重新定义一个命令(即:e)作为别的?
我要重新定义:e *
为:tabe *
。
In vim, in my .vimrc, how can I redefine a command (i.e. :e) as something else?I want to redefine :e *
as :tabe *
.
推荐答案
我想出了一种方法。请参见。从中,我们可以看到,我们可以使用cabbrev来改变命令的作用。为了我的需要, cabbrev e tabe
是完美的。
I figured out a way to do it. See How to disable a built-in command in vim . From that, we can see that we can use cabbrev to change what a command does. For my needs, cabbrev e tabe
is perfect.
但是我们可以推广这个解决方案,使命令以小写字符开头,用户可以访问用户定义的字符:use cabbrev to(re)define a built-in command作为用户定义的。因此,我们可以重新定义内置命令以及用户定义的命令。
But we can generalize this solution to make commands starting with lower case characters accessible to users for user-defined ones: use cabbrev to (re)define a built-in command as a user-defined one. As such, we are able to redefine built-in commands as well as user-defined ones.
这里有一个例子,这相当于我上述的解决我的问题的解决方案:
Here's an example, which is equivalent to my aforementioned solution to my problem:
:command -nargs=+ E :tabe "<args>"
:cabbrev e E
就是这样。
这篇关于Vim:重新定义命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!