在命令模式下将 :E 映射到 :Explore? [英] Map :E to :Explore in command mode?

查看:24
本文介绍了在命令模式下将 :E 映射到 :Explore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 :E 映射到 :Explore?如果我现在执行 :E,我已经安装了导致 E464: Ambiguous use of user-defined command 的扩展,但我的手指不会忘记命令!

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!

我尝试了 map :E :Explore,但这很难看,因为它使访问其他命令变得困难.

I tried map :E :Explore, but that's ugly since it makes accessing the other commands difficult.

我试过这些:

cmap :E<CR> :Explore<CR>
cmap :E^M :Explore^M

(其中 ^M = control-v + enter)但是除非我真的非常快地按 Enter,否则这些都不起作用.

(where ^M = control-v + enter) but these don't work unless I hit enter really really fast.

推荐答案

:E 通常就足够了,如果 :Explore 是唯一以E.您显然定义了多个此类命令,因此 :E 不明确并导致错误.

: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 会导致立即的文字替换,从而产生不需要的副作用.一个稍微好一点的替代方法是 :cabbrev,它可以用来定义命令模式的缩写:

: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

这会在 EEnterESpace 之后触发.前者是需要的,因为输入 :EEnter 将调用 :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.

为了使 :E 正确别名为 :Explore,必须将其定义为单独的命令:

In order for :E to be properly aliased to :Explore, it must be defined as a separate command:

command! E Explore

然而,:command E 列出了所有以 E 开头的已定义命令,显示 :E:Explore 有不同的属性.例如,不可能执行 :E ~ 因为 :E 不接受任何参数.此外,与 :Explore 不同,:E 不会自动完成目录.

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 的定义方式必须与 :Explore 完全相同.执行:verbose command Explore 显示了定义: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 <args>:

command! -nargs=* -bar -bang -count=0 -complete=dir E Explore <args>

虽然可以从 :command Explore 提供的信息中推断出大部分这些属性,但仍然可能存在差异,例如在这种情况下的 -bar.

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.

注意如果定义了 :Explore:Example:Exp:Exa 是最短的明确命令用过的.显式地将 :E 别名为其中之一,如上所述,会覆盖 Vim 的默认行为并允许消除歧义.但是,:Ex 仍然是模棱两可的.

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.

这篇关于在命令模式下将 :E 映射到 :Explore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆