1

I mapped my capslock key to escape but sometimes I accidentally press capslock when I meant to press shift.

Can I remap <Esc>+key to send me back to insert mode and insert the proper character?

For example I would like to press <Esc>+9 and be put back into insert mode and insert the ( character (as if I had just pressed <Shift>+9).

Possible?

user9023
  • 11
  • 1

1 Answers1

3

<Esc> is not a modifier like Shift. There's no <Esc-9> keycode, only <S-9>.

As you usually press Shift before the other key, you could approach this via a set of sequential mappings:

:inoremap <Esc>9 (
:inoremap <Esc>0 )
...

But that would introduce a noticeable delay when you really just want to leave insert mode.

Ingo Karkat
  • 17,819
  • 1
  • 45
  • 61
  • I just tried this (in terminal and gVim), and it only works if I release the Escape key before pressing the 9 key. (If I hold down Escape I only get a 9 inserted.) I'm not clear if that's your intention, or if there's a some setting that affects this behaviour? – Rich Nov 13 '17 at 16:27
  • @Rich That's what I meant by "not a modifier". You have to press them sequentially; there's no setting within Vim. – Ingo Karkat Nov 13 '17 at 19:30
  • The way you've written the second paragraph made me think that you were saying your mapping would work both if the key presses were pressed sequentially (hence, "not a modifier"), but also if the key-presses overlapped, so long as Escape was pressed first. Thanks for clarifying. – Rich Nov 13 '17 at 20:38