# Swap Control key with Capslock Key in x11



## UNIXgod (Jun 12, 2012)

In x11 one may wish to swap the control key with the caps-lock key to put the control key in the home row like terminal keyboards where in the past. This will simplify using the terminal and allow the user to avoid carpal tunnel from the current layout which can only be accomplished via vulcan mind meld finger stretching.

In your user's bin directory create a file called swapkeys.

Put the following code into it and turn on the executable bit:


```
#!/bin/sh

caps2ctrl() {
        xmodmap -e 'remove Lock = Caps_Lock'
        xmodmap -e 'keysym Caps_Lock = Control_L'
        xmodmap -e 'add Control = Control_L'
}
ctrl2caps() {
        xmodmap -e 'remove Control = Control_R'
        xmodmap -e 'keysym Control_R = Caps_Lock'
        xmodmap -e 'add Lock = Caps_Lock'
}
swapkeys() {
        caps2ctrl && ctrl2caps
}
```

In your .xinitrc simply add the line:
`$HOME/.bin/swapkeys &`

vi(1) users may want to also explore swapping the *esc*ape key with the *`~* key


----------

