I want to use <leader>e
to return to normal mode from whatever mode I am in. For insert mode I use
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. I usually have to press <enter>
to execute the command.
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:
*c_CTRL-C*
CTRL-C quit command-line without executing
So just do:
cnoremap <leader>c <c-c>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.