简体   繁体   中英

Using Ctrl + [ instead of ESC in Vim

I want to train my self to avoid hitting the ESC button to exit Insert mode. I want to use Ctrl + [ instead. But after I put this in my .vimrc

inoremap <ESC> <NOP>

I can't use Ctrl + [ either. How can I fix this?

Vim cannot distinguish ESC and Ctrl-[ . If you :h keycode , you will see:

notation    meaning         equivalent  decimal value(s)    ~
-----------------------------------------------------------------------

<Esc>       escape          CTRL-[   27 *escape* *<Esc>*

but you can pull your ESC keycap out. :)

There's no way to do this inside Vim; you'd have to resort to external programs, for example an AutoHotkey hook on Esc that is only active inside the Vim application.

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab> / <CI> , <CR> / <CM> / <Esc> / <C-[> etc. (Only exception is <BS> / <CH> .) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals .

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

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.

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