3

I want to map :e file.txt to :tabnew file.txt, or the equivalent setting for editing file in a new tab. What do I need to put into my vimrc?

4

You probably want to read :h user-commands and put the following in your vimrc:

command! -nargs=1 -complete=file E tabnew <args>

You can't override :e but you can create the command :E which will take one argument (-nargs=1), complete this argument as tabnew does (-complete=file) and executes tabnew with the argument it took.

However as @Hotschke said in comments you probably don't need such a command.

1

Like everyone else, I recommend pretty strongly against doing this, but if you're dead set on the idea (and for future readers who might be doing something slightly different) you could use something like:

:cabbrev <expr> e getcmdline() == 'e' && getcmdtype() == ':' ? 'tabnew' : 'e'

This will replace :e with :tabnew as soon as you type the space after the e. If you find the change too visually jarring, you could perhaps instead set up the the E command from statox's answer and convert :e into :E instead.

See :help :cabbrev for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.