Another addition to the cybernetic memory: how to use xmodmap to swap the alt and ctrl keys on linux. A very useful change if you happen to use Emacs, especially on a laptop.

Step zero

Use the xev program to determine the keycodes for all four keys to be swapped. On my system they were as follows:

  • right-alt 108
  • right-ctrl 105
  • left-alt 64
  • left-ctrl 37

Step one

Create a .Xmodmap file. Here’s mine; if your key codes are not the same as mine
adjust accordingly.

clear control
clear mod1
keycode 37 = Alt_L Meta_L
keycode 64 = Control_L
keycode 105 = Alt_R Meta_R
keycode 108 = Control_R
add control = Control_L Control_R
add mod1 = Alt_L Meta_L Alt_R Meta_R


Find a way to get the .Xmodmap file to run at startup. This is unfortunately distro and version specific. I am running Linux Mint 14, the following worked for me. Open menu::preferences::Starup Applications. Then add a new entry containing the command xmodmap ~/home/drc/.Xmodmap (adjust path to your .Xmodmap as needed). I suspect using an ~/.Xmodmap file would also have worked, but I did not try it.