Home The Quantizer> Tutorials> How to remap keys in Ubuntu xmodmap [+Video]

How to remap keys in Ubuntu xmodmap [+Video]

When ever I’m using a macbook and running Ubuntu in a VM I like to swap the left command and left control keys so this page shows how remap keys in Ubuntu.

Figure out the keycode

The first thing we need to do is figure out what keycodes are for the keys we want to remap. One easy way to do that is with the xev command. Execute xev in the terminal and start pressing keyboard keys to find the keycodes you will want to remap.

xev output

Create Xmodmap file

Create a file in your home directory named .Xmodmap

vi ~/.Xmodmap

Add the following to remap keyboard keys left control and left command/super

clear mod4

keycode 105 =
keycode 206 =

keycode 133 = Control_L NoSymbol Control_L
keycode 134 = Control_R NoSymbol Control_R
keycode 37 = Super_L NoSymbol Super_L

add control = Control_L
add control = Control_R
add mod4 = Super_L

Test key mapping

xmodmap ~/.Xmodmap

This will only work for the current session, after rebooting the key mapping will be restored to the default

Apply Key mapping on Startup

Open Startup Applications Preferences by clicking Activities and searching for the Startup Applications Preferences

startup application

Create a new startup program using the following command, don’t forget to use your user name

/usr/bin/xmodmap /home/<your user name here>/.Xmodmap
startup program

That is it! Now every time on boot the key remapping will happen and the left control and left command keys will be switched.