32
: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.
如果:Explore是由E开始的唯一定义的命令,那么它就足够了。显然,你已经定义了多个这样的命令,所以E是不明确的,结果是错误的。
: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:
:cmap会导致直接的文字替换,因此会产生不必要的副作用。更好的选择是:cabbrev,它可以用来定义命令模式的缩写:
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.
这将触发EEnter或ESpace。前者是需要的,因为输入:EEnter会调用:Explore,但后者在命令模式下会有副作用。
In order for :E
to be properly aliased to :Explore
, it must be defined as a separate command:
为了使E能够正确地别名:Explore,它必须被定义为一个单独的命令:
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.
但是,命令E,它列出从E开始的所有定义的命令,显示:E和:Explore具有不同的属性。例如,不可能执行:E ~因为:E不接受任何参数。另外,不像:Explore,:E不自动完成目录。
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
:
为了弥补这些不足,E必须以完全相同的方式定义:探索。执行:verbose命令探索显示了脚本的位置:定义了Explore;:E可以用同样的方式定义,加上
:
command! -nargs=* -bar -bang -count=0 -complete=dir E Explore
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.
虽然可以从以下提供的信息中推断出这些属性的大部分,但是仍然存在差异,比如在这种情况下的-bar。
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.
如果:Explore和:Example被定义,Exp和:Exa是可以使用的最短的、明确的命令。显式别名:E的其中一个,如上所述,重写了Vim的默认行为,并允许消除歧义。然而,Ex仍然是模棱两可的。