Skip to content

Instantly share code, notes, and snippets.

@dchenk
Last active November 15, 2023 07:47
Show Gist options
  • Save dchenk/8774d728fce124e5158188e7942762ce to your computer and use it in GitHub Desktop.
Save dchenk/8774d728fce124e5158188e7942762ce to your computer and use it in GitHub Desktop.
Swap CTRL and ALT keys on GNOME

Swap CTRL and ALT keys on GNOME

From here: https://askubuntu.com/a/101877

Create a file called .Xmodmap in your home directory.

$ vim ~/.Xmodmap

Add the following lines to the file:

clear control
clear mod1
keycode 37 = Alt_L Meta_L
keycode 64 = Control_L
add control = Control_L Control_R
add mod1 = Alt_L Meta_L

Save the file. Next time you login the new key mappings will be active. To have the settings take immediate effect run the command:

$ xmodmap ~/.Xmodmap

There's a chance that the keycodes above are different on your computer. If the above doesn't work, try running the xev program from the command line. Xev will generate a new small window in the corner of your screen. If you start pressing keys on your keyboard you’ll get all the key mapping information for that key press.

@khal3d
Copy link

khal3d commented Nov 15, 2023

The default login method for Ubuntu no longer supports Xmodmap. To regain this functionality, you must log in using the "Ubuntu with Xorg" option.

To switch to Xorg, log out of your current session. Upon reaching the login screen, locate the gear icon before entering your password. Click on this icon to select the "Ubuntu on Xorg" session. This preference will be retained until you choose to change it again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment