I'd like to switch my Ctrl and Alt keys under Linux (to make it more Mac-like). How do I do this?

If it helps, I'm running Ubuntu 9.04.


First off, try looking in Preferences > Keyboard > Layouts > Layout Options under the Alt/Win key behavior if there is a suitable option there for you.

If that doesn't do it for you, these xmodmap commands would switch left Ctrl with left Alt (at least with my keyboard).

xmodmap -e 'keycode 37 = Alt_L  ISO_Prev_Group ISO_Prev_Group NoSymbol ISO_Prev_Group' 
xmodmap -e 'keycode 64 = Control_L' 

To get your keycode, you can run the program xev in a terminal window and press first Ctrl and note the keycode, then Alt to get the keycode.

| improve this answer | |
  • 1
    What is that "ISO_Prev_Group ISO_Prev_Group NoSymbol ISO_Prev_Group" part? – Samuel Lampa Jul 24 '13 at 19:34

xmodmap - utility for modifying keymaps and pointer button mappings in X

showkey - examine the codes sent by the keyboard

setkeycodes - load kernel scancode-to-keycode mapping table entries

| improve this answer | |
  • 1
    Running showkey produces the error, "Couldnt get a file descriptor referring to the console." Looks like this has happened to a few others on the net...hope it's just my system and not (K)ubuntu's setup. – Nikhil Chelliah Jul 15 '09 at 15:16
  • 2
    @Nikhil Chelliah - showkey and setkeycodes are system level so you'd need to sudo them. – mas Jul 15 '09 at 15:56

Do the following steps:

  1. Create a new file. Let's call it remap.txt.

  2. Add the following text to the file:

    ! Swap Alt_L and Control_L
    remove mod1 = Alt_L
    remove Control = Control_L
    keysym Control_L = Alt_L
    keysym Alt_L = Control_L
    add mod1 = Alt_L
    add Control = Control_L

    The above is like a script for xmodmap. It will change the current key bindings.

  3. Run the following commands to run the script:

    # xmodmap remap.txt
  4. (optional) To load the same settings after reboot run:

    # sudo dumpkeys > ~/.Xmodmap
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.