Ubuntu – How to invert Ctrl and Cmd on a Macbook Pro keyboard

keyboardmacbookshortcut-keysunity

using Mac computers for few years, I got accustomed of using the Cmd key on the keyboard as a standard Ctrl key.

With Ubuntu 13.04 on my Macbook Pro 5,3 (2009), the Cmd is used for Unity controls, and Ctrl for applications shortcuts. Is there any way to switch the two keys? So that, as an example, close a tab in Firefox would be Cmd+W instead of Ctrl+W?

Best Answer

I found out a workaround. The solution is to use the xmodmap utility and make it load a personal file with the correct mapping for the keyboard.

  1. Open a terminal and create a new file in your /home folder, lets call it .Xmodmap

    nano .Xmodmap
    

    (I use nano as a nice text editor inside the console, you can use Gedit instead, install nano with the command sudo apt-get install nano if you'd like to test it, it's quite obvious to handle.)

  2. Copy/paste the following content to the new file:

    clear control
    clear mod4
    
    keycode 105 =
    keycode 206 =
    
    keycode 133 = Control_L NoSymbol Control_L
    keycode 134 = Control_R NoSymbol Control_R
    keycode 37 = Super_L NoSymbol Super_L
    
    add control = Control_L
    add control = Control_R
    add mod4 = Super_L
    
  3. Make the file executable.

    chmod +x .Xmodmap
    
  4. Test it now with the following command:

    xmodmap .Xmodmap
    

    The dash should now appear with Ctrl instead of CMD, hurra!

  5. Now we want the file to be executed each time the system starts up. Open the Startup Applications utility and add a new entry, name it as you want and put the following comand in it:

    /user/bin/xmodmap /home/YOURUSERNAME/.Xmodmap
    

Reboot, it should be ok. If it is not, you should add a .xinitrc file in your /Home folder, and add the command inside it. The .xinitrc file will be read by the system while loading the desktop environment.