How can I remap the Capslock key to ESC in a Windows Cygwin shell?

Ideally I would only remap the value in Cygwin shells instead of everywhere, preserving behavior in other apps (although admittedly even in Windows I think I probably hit the Capslock key more frequently by accident than on purpose).

Even better would be something I could add to my bashrc, making it easily portable.

Background: I spend most of my time in Linux where I've used xmodmap (like this, http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_XWindows) to remap Capslock to Esc for speed and comfort with vi. This works great everywhere on those systems, i.e. in vim and also on a bash commandline. For the remaining time when I'm in Cygwin on a windows box, my muscle memory has me hitting the capslock key to ill effect!


I do the remapping system-wide via the registry modification outlined at http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_Windows.

On the same page, there's also an AutoHotkey solution.

You can limit the scope of AutoHotkey remappings like this, which should (untested!) limit to Windows console windows:

#IfWinActive ahk_class ConsoleWindowClass

If you use the new Mintty-based Cygwin Terminal, that would then apply exclusively to Cygwin. (But I'd still recommend you try the system-wide remapping first; I've put Caps Lock on Scroll Lock as a fallback, but I rarely if ever use it.)

| improve this answer | |
  • +1 for AutoHotKey. Although it is ludicrous that remapping keys is so difficult in Windows. – Prince Goulash Nov 28 '12 at 13:10

I do not know how to remap Capslock only in Cygwin. But in Windows 7 globally remap

CapsLock to Esc just add a register key:

[HKEY_CURRENT_USER\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00

CapsLock to Ctrl:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

Use Current_User or Local_Machine whatever meets your needs better.

Other mappings

| improve this answer | |

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.