Vim command to map CapsLock to Escape

5

5

What command do I have to enter to be able to leave editmode by pressing CapsLock in Vim?

Christian

Posted 2009-07-30T22:31:04.930

Reputation: 1 750

Answers

11

In Linux, use the xmodmap utility

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

In Windows, you can use AutoHotkeys, or change your registry settings.

See this tip from Vim wiki for detailed instructions for Windows and also the linked tip for Linux.

user4126

Posted 2009-07-30T22:31:04.930

Reputation: 546

Note that there is a bug in some new versions of linux (Ubuntu 10.04, for example) that prevents this from working. More info here (https://bugs.launchpad.net/ubuntu/+source/x11-xserver-utils/+bug/576102) and here (https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/524774)

– intuited – 2010-06-08T21:28:45.863

4

In Ubuntu 9.04 using Gnome, this is most easily accomplished via the GUI. Go to System -> Preferences -> Keyboard, switch to the "Layouts" tab and click the "Layout Options" button. You'll find several "Caps Lock key behaviors" there to choose from. You can make CapsLock and additional Escape and you can swap both, e.g.

innaM

Posted 2009-07-30T22:31:04.930

Reputation: 9 208

2

Unfortunately, it's not as simple as just entering a command, but it is a well-investigated topic. I'd go with the AutoHotkey method, if I were you.

chaos

Posted 2009-07-30T22:31:04.930

Reputation: 1 599