views:

776

answers:

4

I'm using GVIM under Windows. And want to map CAPSLOCK to Ctrl+^

Any way to do this?

Btw, I see tons of samples over the web how to swap CAPS and Esc using registry hack, but none of them use VIM map command, instead external tools and registry changes.

+3  A: 

I dont think you can. I believe CAPS-LOCK is probably translated by the OS before vim ever sees it. So you'd need to do a hack at the OS level, like the registry hacks you've already seen.

EDIT: autohotkey looks like it could be used to bridge the vim-OS gap. This way a thirdparty app is doing the hacks at the OS level, and you're just hooking that app.

Michael Anderson
+4  A: 

Capslock (and Control, and Shift etc.) is a modifier key, which means that it's used with another normal key to modify the meaning of that key. AFAIK the OS does not pass the modifier keys to the application unless a normal key has also been pressed, e.g. pressing CTRL will not be seen by the application, but CTRL-C will be.

liwp
Not quite. It is perfectly possible for an application to detect ctrl, shift, alt and windows key presses. The problem with keys like Caps Lock and Num Lock is that the OS insists on interpreting them as a toggling key.
Wim Coenen
+1  A: 

Under windows? Use AutoHotkey. It's not a vim mapping, but as the others have stated you can't map it. I use AHK to map my CAPSLOCK to CTRL.

hometoast
+3  A: 

Linux? With X, use xmodmap to alter the key mapping, e.g.

xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'

Will map Esc to the CapsLock key. Google for more examples.

Dan Andreatta