如何在 Vim 中重新定义命令? [英] How to redefine a command in Vim?
问题描述
在 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 来更改命令的作用.对于我的需要,cabrev 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.
但我们可以概括这个解决方案,使用户可以访问以小写字符开头的命令以用于用户定义的命令:使用 cabbrev 将内置命令(重新)定义为用户定义的命令.因此,我们能够重新定义内置命令以及用户定义的命令.
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 中重新定义命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!