When I noremap my Esc key, it breaks other things even though I'm not pressing Esc and those other mappings are also noremap.

I start with this vimrc:

set nocompatible
inoremap <silent> <Up> <esc><Up>
inoremap <silent> <Down> <esc><Down>

which lets me use the up and down arrows to escape. Everything works fine with just the above. And I'm trying to break my Esc-pushing habit so I added:

inoremap <esc> <nop>

But now when I hit my up arrow in insert mode it simply inserts 0A and down it inserts 0B and leaves me in insert mode. How could this mapping cause this problem when I'm not even when I'm not pressing Esc and everything is set to noremap?

  • 1
    Press Ctrl-V and then Up, you'll find Up itself is a composite key code, starting with Esc.
    – muru
    May 22 '20 at 19:04
  • @muru My Ctrl-V results are slightly different ^[0A vs ^[[A, but the takeaway is the same since the ^[ which I recognize as a shortcut for escape is actually the actual composite key code of escape (Ctrl-V esc produces ^[ ). Fortunately for me I only wanted this temporarily to break my habit, so I guess I'll live without this remap. Thanks for your help, that did answer my question even if not the results I was hoping for.
    – Dan
    May 22 '20 at 19:32
  • Welcome to Vi and Vim Dan!
    – D. Ben Knoble
    May 22 '20 at 21:13

Browse other questions tagged or ask your own question.