Linux + Xorg : Remapping caps lock key to escape

In this post I’ll revisit the classical “how to remap caps lock into something useful” once again. In this post, I’ll show how to remap the caps lock key to have an extra Escape key, which is very useful for all VI/Vim users.

Method 1 : Using xmodmap

This is mostly the usual way of altering the keyboard map. All you have to do edit the ${HOME}/.Xmodmap file like below :

clear Lock
keycode 66 = Escape

This file is often sourced when your X sessions is opened, but there are numerous bug reports stating that it’s either ignored or overridden by some windows managers.

You might need to source the file by running xmodmap ~/.Xmodmap at some point after the windows manager is started.

Method 2 : Using XKB configuration

If you let Xorg setup your keyboard by consulting HAL, you can remap the caps lock key to escape by having the following policy file in /etc/hal/fdi/policy/keyboard.fdi



        
        
                
                        evdev
                        caps:escape
                        us
                        intl
                
        
        

The caps:escape takes care of setting up caps lock as an escape key.

See more about How to setup Xorg according to HAL

If you don’t use HAL and prefer to setup your keyboard through xorg.conf, it will look like the snippet below :

Section "InputDevice"
    Identifier "Keyboard1"
    Driver "evdev"

    Option "XkbLayout" "us"
    Option "XkbVarian" "intl"
    Option "XKbOptions" "caps:escape"
EndSection

To see the other available options, check /usr/share/X11/xkb/rules/xorg

Further readings :