Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Ctrl + [ instead of ESC in Vim

Tags:

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?

like image 293
Methuz Kaewsai-kao Avatar asked May 19 '26 00:05

Methuz Kaewsai-kao


2 Answers

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. :)

like image 101
Kent Avatar answered May 21 '26 22:05

Kent


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> / <C-I>, <CR> / <C-M> / <Esc> / <C-[> etc. (Only exception is <BS> / <C-H>.) 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.

like image 44
Ingo Karkat Avatar answered May 21 '26 21:05

Ingo Karkat