Linux: Swap Control Alt Keys, xmodmap

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.

Linux Keybinding Topic

  1. Linux: Keyboard Software Guide
  2. Linux: Swap Control Alt Keys, xmodmap
  3. Linux: Set F2 F3 F4 to Cut Copy Paste
  4. Linux: Swap CapsLock Escape Keys
  5. Linux: Make CapsLock Do Home Key
  6. Linux: Setup Shift Lock Key
  7. Linux: Add Keyboard Shortcut to Switch App
  8. Linux: Set Key Repeat Rate
  9. Linux: Set System Keyboard Layout
  10. Linux: How to Switch to Dvorak Keyboard Layout
  11. Linux: Change Volume by Command
  12. Linux: xmodmap Tutorial
  13. Linux: Xbindkeys Tutorial
  14. Linux: Find Keyboard Key Scancode
  15. Linux: X11 Keyboard Key Names