如何在Vim中重新定义命令? [英] How to redefine a command in Vim?

查看:138
本文介绍了如何在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 *.

推荐答案

我想出了一种方法.请参阅如何在vim .由此可见,我们可以使用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.

但是我们可以推广这种解决方案,使用户可以使用以小写字母开头的命令来访问用户定义的命令:使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆