:E
would normally suffice as is if :Explore
were the only defined command that began with an E
. You evidently have multiple such commands defined, so :E
is ambiguous and results in an error.
:cmap
causes immediate literal substitution and thus has unwanted side effects. A slightly better alternative is :cabbrev
, which can be used to define abbreviations for command mode:
cabbrev E Explore
This triggers following EEnter or ESpace. The former is desired because typing :EEnter will invoke :Explore
, but the latter again has side effects in command mode.
In order for :E
to be properly aliased to :Explore
, it must be defined as a separate command:
command! E Explore
However, :command E
, which lists all defined commands that start with E
, reveals that :E
and :Explore
have different properties. For example, it's impossible to execute :E ~
because :E
does not accept any arguments. Also, unlike :Explore
, :E
does not autocomplete directories.
To remedy these deficiencies, :E
must be defined in exactly the same way as :Explore
. Executing :verbose command Explore
shows the location of the script in which :Explore
is defined; :E
can then be defined in the same manner, with the addition of <args>
:
command! -nargs=* -bar -bang -count=0 -complete=dir E Explore <args>
While it's possible to deduce most of these attributes from the information provided by :command Explore
, there can still be discrepancies, such as -bar
in this case.
N.B. If :Explore
and :Example
are defined, :Exp
and :Exa
are the shortest unambiguous commands that can be used. Explicitly aliasing :E
to one of them, as above, overrides Vim's default behavior and allows for disambiguation. However, :Ex
would still be ambiguous.