views:

540

answers:

4

I saw the vim wiki tips and it says that in order to remap Esc to CAP LOCK you have to edit the following windows code:

REGEDIT4
[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

Is it possible to remap Esc to CAP LOCK by only adding or modifying lines in the _vimrc?

+8  A: 

I recommend that you use AutoHotkey for this.

You can do a per-application hotkey change:

SetTitleMatchMode,2
#IfWinActive,VIM
   CAPSLOCK::ESC
return

#IfWinActive
   CAPSLOCK::CTRL
return

This script, for example sets caps to escape in vim, and control everywhere else.

Jay
AutoHotkey is great
janoChen
+1  A: 

There's no vim key identifier for the capslock key, so you have to do it with a scan code.

It would be like trying to map the ctrl key or the shift key to something - those keys don't do anything by themselves, they are key modifiers, so they can't be trapped the same way.

Jansen Price
A: 

The mapping has to be done at the OS level instead of vim, so the complication comes from the OS. For example, on my Ubuntu machine I have the following in ~/.Xmodmap:

! Esc on caps lock
remove Lock = Caps_Lock
keysym Caps_Lock = Escape

However, I don't think the REGEDIT script is so bad. It's kind of ugly, but it's only two lines!

Permanuno
Easier: `setxkbmap -option caps:escape` or add that to the relevant section of the X/input configuration.
ephemient