I'm trying to map a combination of left alt and return keys in my .vimrc, yet without success.

I've added all those mappings to my .vimrc file, with no effect:

map <M-esc> itest0<return><esc>
map <M-cr> itest1<return><esc>
map <M-return> itest2<return><esc>
map <M-enter> itest3<return><esc>
map <M-[> itest4<return><esc>
map ^[ itest5<return><esc>

Some info:

After pressing Ctrl+v and then Alt+return:

  • in my terminal i get ^[
  • in vim (and gvim) in insert mode i get ^[
  • After calling sed -n l i get:

I'm using terminator on Arch Linux. Behaviour described is identical no matter whether I use vim or gvim. What am I supposed to do?


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>.) Same applies to Alt and non-alphabetic keys. 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, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

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 release.

  • gVim 8.2.2118: <M/C-Enter> and <M/C-Esc> both work for me. (Linux Mint 20) – Zoe Dec 14 '20 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.