Linux: Swap Control Alt Keys

By Xah Lee. Date: . Last updated: .

This page shows you how to swap {Ctrl, Alt} keys on Linux.

Create a file at ~/.Xmodmap. The file content should be this:

! -*- coding: utf-8 -*-
! 2013-02-04

! swap Ctrl and Alt keys

! here's the default setting on special keys
!  xmodmap -pke | grep -P '(Control|Super|Alt|Menu)'

! keycode  37 = Control_L NoSymbol Control_L
! keycode  64 = Alt_L Meta_L Alt_L Meta_L
! keycode 105 = Control_R NoSymbol Control_R
! keycode 108 = Alt_R Meta_R Alt_R Meta_R
! keycode 133 = Super_L NoSymbol Super_L
! keycode 134 = Super_R NoSymbol Super_R
! keycode 135 = Menu NoSymbol Menu
! keycode 147 = XF86MenuKB NoSymbol XF86MenuKB
! keycode 204 = NoSymbol Alt_L NoSymbol Alt_L
! keycode 206 = NoSymbol Super_L NoSymbol Super_L

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

Now, run this line in terminal:

xmodmap ~/.Xmodmap

That's it. When X11 starts, that file will be loaded automatically.

For Mac and Microsoft Windows, see

How to Swap CapsLock Ctrl Alt Cmd Keys

Linux Keybinding Howto

Mouse

Linux Desktop keys