Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redefine a command in Vim?

In vim, in my .vimrc, how can I redefine a command (i.e. :e) as something else? I want to redefine :e * as :tabe *.

like image 394
Yktula Avatar asked Apr 09 '10 04:04

Yktula


1 Answers

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.

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

That's all.

like image 189
Yktula Avatar answered Sep 29 '22 10:09

Yktula