11

I have read the following:

1. How to cleanly swap alt and ctrl keys in xubuntu?

2. How to swap Command and Control keys with xkb step by step?

Other than the above, I also spent quite some time on google and xkb documentation.

I assume, that many users like me switching from Mac to Ubuntu would like to swap the ctrl and alt keys immediately after finishing the installation.

My purpose to post this question (and answer) here is to give a quick solution instead of spending so much time going through the above threads and docs.

Also, none of the above provide the correct answer. (This is not to say that I don't appreciate the help. The above posts did ultimately help me achieve what I wanted to but the responses were not complete.)

Thread 1 only swaps left ctrl with left alt

Thread 2 swaps ctrl and win even though the question was not about win key

13
  1. Edit the file /usr/share/X11/xkb/symbols/ctrl to add the following lines to swap Right Alt with Right Ctrl key:

    // Swap the functions of the right Alt key and the right Ctrl key.
    partial modifier_keys
    xkb_symbols "swap_ralt_rctl" {
        replace key <RALT> { [ Control_R, Control_R ] };
        replace key <RCTL> { [ Alt_R, Meta_R ] };
    };
    

    Similarly you can add lines to swap Left Alt with Left Ctrl.

  2. Edit the file /usr/share/X11/xkb/rules/evdev.lst to dd the following line in the ! option section:

    ctrl:swap_ralt_rctl Swap Right Alt key with Right Ctrl key
    
  3. Edit the file /usr/share/X11/xkb/rules/evdev to add the following line in the !option = symbols section:

    ctrl:swap_ralt_rctl = +ctrl(swap_ralt_rctl)
    
  4. Use dconf from dashboard (if necessary install it with apt-get install dconf-tools) and either of the following methods:

    • Open dconf editor from dashboard and navigate to the key /org/gnome/desktop/input-sources/xkb-options and set its value to:

      ['ctrl:swap_lalt_lctl','ctrl:swap_ralt_rctl']
      
    • Use dconf from terminal (probably the command below should work instead of the previous step, but I am not sure about it):

      dconf write "/org/gnome/desktop/input-sources/xkb-options" "['ctrl:swap_lalt_lctl','ctrl:swap_ralt_rctl']"
      
  • 1
    Worked for me, but the correct mappings were already present in all files on my system. All that was necessary for me was the last command, which does work as written. – Mack Apr 22 '17 at 20:42
  • 1
    Nice steps! Thx – BurningKrome Sep 17 '17 at 14:19
4

For those using the GNOME Desktop, this can be done via GUI. First install the GNOME Tweak Tool from the software center, then run it. You can then check the relevant checkboxes:

GNOME Tweak Tool

  • No option to swap right side ctrl and alt though – bruddha Jan 24 at 4:04

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.