1

I'm new to vim, and I find using <Esc> to enter normal mode to be slow. I'm on Windows. I seldom use the <Alt> keys (left and right) when I'm editing text. It should be convenient to use <Alt> to enter normal mode instead. What should I enter into my vimrc use <Alt> instead of <Esc> to enter normal mode ?

I found articles online that explain this for MAC, but I could not find one for Windows.

5
  • 1
    You’d have to do this at a hardware/OS level, since Alt by itself does not send a code Vim can capture. This how I have Caps Lock perform Control: at the OS level.
    – D. Ben Knoble
    Mar 9, 2019 at 20:14
  • You can't really do what you're asking from vim, you would need to do it on an OS level. This is because vim doesn't handle the key_press and key_release events separately, for vim key_press is the key press. So, the modifier keys really have no way to be mapped to be other keys. I'm not very familiar with windows except from a gamer's perspective, so I'm no help there.
    – 3N4N
    Mar 9, 2019 at 20:16
  • 1
    Thanks for your comment Knoble and klaus. Could you please show me how it should be done at the OS level ? Point me to some resource that I can follow.
    – rranjik
    Mar 9, 2019 at 21:23
  • 1
    Maybe AutoHotkey.
    – Ralf
    Mar 9, 2019 at 22:19
  • 1
    @Ralf thanks! Someone please make a clear answer that this cannot be done in the usual way (requires some hacking). I will accept, and close this. It should be helpful for others (I searched this on the internet for a very long time before I decided to ask here!).
    – rranjik
    Mar 9, 2019 at 23:14

1 Answer 1

1

The Alt can't be mapped, as it is a "modifier". It is only detectable if it used together with some other key, like Alt-F.

To prove that, do the following:

Open Vim, change into insert mode and hit Ctrl-V. Then hold down the Alt key. Nothing happens. Only after you hit another key, some input appears.

If you want to map the Alt key alone, you have to reassign the Alt key on the OS level. For Windows that might be done with Autohotkey (not tested).

BTW: Reassigning Alt globally will affect all programs, but Autohotkey seems to have context-sensitive hotkeys.

If you want to map Alt-something, search Vi and Vim Stackexchange, there are several questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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