简体   繁体   English

在命令行模式下为Vim重新映射Esc

[英]Remap Esc in Command Line Mode for Vim

I want to use <leader>e to return to normal mode from whatever mode I am in. For insert mode I use 我想使用<leader>e从我所处的任何模式返回正常模式。对于插入模式,我使用

inoremap <leader>e <esc>

I wanted the same thing to exit command line mode, so I wrote 我希望退出命令行模式也是一样,所以我写了

cnoremap <leader>c <esc>

However, when it exits command line mode, it tries to execute whatever what written past the command line. 但是,当退出命令行模式时,它将尝试执行通过命令行编写的所有内容。 However, when I just use <esc> normally, it exists command line mode without executing anything. 但是,当我通常只使用<esc> ,它存在命令行模式而不执行任何操作。 I usually have to press <enter> to execute the command. 我通常必须按<enter>来执行命令。

Can anyone help me understand what is going on here, and what I can do to get the behavior I want. 任何人都可以帮助我了解这里发生的事情以及如何做才能得到我想要的行为。

Thanks! 谢谢!

According to help: 根据帮助:

CTRL-[                      *c_CTRL-[* *c_<Esc>* *c_Esc*
<Esc>       When typed and 'x' not present in 'cpoptions', quit
        Command-line mode without executing.  In macros or when 'x'
        present in 'cpoptions', start entered command.

It seems "in macros" applies to right-hand side of a mapping too (well, it's not "typed"). 似乎“在宏中”也适用于映射的右侧(嗯,它不是“类型化的”)。 You can use CTRL-C instead as it will never execute the command: 您可以改用CTRL-C ,因为它将永远不会执行以下命令:

                            *c_CTRL-C*
CTRL-C      quit command-line without executing

So just do: 所以做:

cnoremap <leader>c <c-c>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM