Vim logo vim online Vim Book Ad

basic Tip #166: Mapping caps lock to esc in XWindows

 tip karma   Rating 70/22, Viewed by 845 

created:   November 19, 2001 11:19      complexity:   basic
author:   Leif Wickland      as of Vim:   5.7

(This originally appeared on the vim mailing list as post by Adam Monsen http://groups.yahoo.com/group/vim/message/19856)

If you want to completely swap caps lock and escape, you have to replace the
"Lock" on caps lock. Drop this file in your home dir:<br>
-----------start------------<br>
! Swap caps lock and escape<br>
remove Lock = Caps_Lock<br>
keysym Escape = Caps_Lock<br>
keysym Caps_Lock = Escape<br>
add Lock = Caps_Lock<br>
------------end-------------<br>
and call it ".speedswapper". Then open a terminal and type<br>
$ xmodmap .speedswapper<br>
and you'll be twice as efficient in vim. Who needs caps lock anyway? The swapping lasts for the duration of the X session, so you can put it in a .xinitrc or similar startup file. As far as other people using my laptop, I'd rather they didn't! Using a Dvorak layout might protect me even more... :)

 rate this tip  Life Changing Helpful Unfulfilling 

<<Deleting a buffer without closing the window | Using vim as a man-page viewer under Unix >>

Additional Notes

leifw @at@ bigfoot dot.dot com, November 19, 2001 11:21
Oh, and I really didn't mean for those <br>'s to show up in the file.  It should look like
-----------start------------
! Swap caps lock and escape
remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock
------------end-------------
[email protected], July 2, 2002 21:06
Great tip!!! And I might try the other tip on the Dvorak mappings :-)
[email protected], October 3, 2002 23:38
If you want to use the capslock as escape on the console as opposed to just in X, try:

loadkeys ~/keymap

where ~/keymap contains:

---------->8----------
keycode 58 = Escape
----------8<----------

Or, if you want to completely swap them:

---------->8----------
keycode 1 = Caps_Lock
keycode 58 = Escape
----------8<----------

see 'man 5 keymaps', and verify with 'dumpkeys' that keycode 1 is Escape and keycode 58 is Caps_Lock beforehand :)
[email protected], October 12, 2002 11:05
hehe, nice, very nice...  but i'm living in a torture right now, because i DO wanna change <esc> to another key closer, *** but i'm so used to <esc> that i can't !!!! ***

damn. :P
[email protected], January 22, 2003 3:23
How to do this in windows:  Create the following file, calling it capstoesc.reg:

-------start
REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\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
--------end

Then double-click on it and reboot.

The syntax is explained in https://www.vim8.org/tip_view.php?tip_id=285
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo