How can I map :E to :Explore? I've installed an extension that leads to E464: Ambiguous use of user-defined command if I do :E now, but my fingers won't forget the command!
I tried map :E :Explore, but that's ugly since it makes accessing the other commands difficult.
I tried these:
cmap :E<CR> :Explore<CR>
cmap :E^M :Explore^M
(where ^M = control-v + enter) but these don't work unless I hit enter really really fast.
: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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With