setxkbmap


How to use setxkbmap to rebind Caps Lock

Caps Lock must be the second most useless key on my keyboard (what does Scroll Lock even do?) and one of the first things I usually do after installing a new Linux system is to rebind it to something useful, such as backspace. This is very easy to do (in X11 at least). Just call this script on login.

#!/bin/sh

#Set the keyboard layout to "Swedish" 
setxkbmap -layout se

#Replace Caps Lock with Backspace
setxkbmap -option caps:backspace

#Required to allow key repeat
xmodmap -e "clear Lock"

You can replace Caps Lock with other keys by changing ‘caps:backspace’ to whatever you want.

Replace Caps lock with escape:

setxkbmap -option caps:escape

Replace Caps Lock with Ctrl:

setxkbmap -option ctrl:nocaps

Reset all options and bindings:

setxkbmap -option