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?

9
  • 2
    Unfortunately, I'm pretty sure this is not possible. See this answer.
    – Tumbler41
    Aug 26, 2016 at 21:59
  • @Tumbler41 Isn't that about mapping to ctrl rather than <esc>?
    – DJMcMayhem
    Aug 26, 2016 at 22:10
  • 1
    "I mapped my capslock key to escape" -> How did you do this? In Vim or in your operating system? Aug 26, 2016 at 22:27
  • @Carpetsmoker I thought that wasn't possible to do that in Vim and doing it in the OS level was the only way. Have I missed something?
    – statox
    Aug 29, 2016 at 7:16
  • @statox Dunno ... But seems to me that asking to be sure is always a good idea ;-) Aug 29, 2016 at 7:50

1 Answer 1

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.

3
  • 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, 2017 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. Nov 13, 2017 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, 2017 at 20:38

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.