Loading
May 26, 2012

Configure the keyboard for your Macbook and Ubuntu 12.04 (and 12.10)

Ubuntu in the MacBook Pro

I love the new Ubuntu 12.04 Precise Pangolin. Unity – and the graphics drivers – have finally reached a stability that satisfies me and let me keep GNU/Linux as solo operating systems on my Macbook Pro 6,2.

What drives me crazy is the default keyboard mapping, surely not thought for who owns an Apple computer.

First, the Unity Launcher (a.k.a. Dash) default shortcut is the Super key (or Win key). This key corresponds to the cmd key on Apple keyboards.
Under Mac OS X, the combination cmd+space opens Spotlight, while cmd+c, cmd+v are for Copy&Paste. That is, the cmd key is a supercharged ctrl key.

I spent some time to search the best combinations to reproduce this behavior under Ubuntu.
Here is what I managed to create:

  • I swapped the left ctrl and the left/right cmd keys. That is, cmd becomes ctrl and ctrl becomes cmd
  • After the first modification, it becomes unconvenient to open Dash with the ctrl key. Therefore, I changed Unity Launcher key to cmd+space. This (sort of) emulates OS X behavior.

To implement the first tweak, create the file ~/.Xmodmap with the following content:

Logout and login again.
Congratulations, you have the swapped keys. Ubuntu should already take care to load the file automatically.

It is important to not manually load the .Xmodmap file. It may result in a double application of the mappings, resulting in a re-swap of the keys.

To achieve the second tweak, install the package compizconfig-settings-manager.
Open it using the ccsm command, or search for it in Dash.
Find Ubuntu Unity Plugin->Behavior->Key to show the launcher and change it to <Primary>space, using the Grab key combination button. It may be also shown as <Control><Primary>space.

You can now have a behavior similar to Mac OS X in Ubuntu 12.04. You can change the virtual desktop using cmd+alt+arrow. You can cut, copy, and paste using cmd+x, cmd+c, and cmd+v. You can open the Unity launcher with cmd+x.

I hope that this little how-to can help frustrated Apple users who want to embrace GNU/Linux freedom.

(Featured Image credits: Marco Antonio Islas Cruz)

written by dgraziotin

Dr. Daniel Graziotin received his PhD in computer science, software engineering at the Free University of Bozen-Bolzano, Italy. His research interests include human aspects in empirical software engineering with psychological measurements, Web engineering, and open science. He researches, publishes, and reviews for venues in software engineering, human-computer interaction, and psychology. Daniel is the founder of the psychoempirical software engineering discipline and guidelines. He is associate editor at the Journal of Open Research Software, academic editor at the Research Ideas and Outcomes (RIO) journal, and academic editor at the Open Communications in Computer Science journal. He is the local coordinator of the Italian Open science local group for the Open Knowledge Foundation. He is a member of ACM, SIGSOFT, and IEEE.

Comments
  • S. Surashu Aug 17, 2012 Reply

    I tried doing this as well but it just doesn’t fit the keyboard scheme in Ubuntu so I just reverted back. I somehow already have a feel for the keyboard shortcuts anyway since I’ve used both Windows and mac.

    • dgraziotin Aug 19, 2012 Reply

      In which sense it does not fit the keyboard scheme? Are there no more working keys on your keyboard after my instructions?
      By the way, I re-installed Ubuntu 12.04 today and I can confirm this tutorial is working for me.

  • Jhonny Everson Aug 28, 2012 Reply

    Hello, does the cmd+space work with Gnome 3 instead of Unity? The first tweak worked great but I cannot get the second to work. Any help appreciated.

  • Edward Coast Sep 7, 2012 Reply

    I’m using a Mac keyboard on Linux Mint 13 – Mate. I selected an option for the command key to act like a control key. This is OK for most things, but in Terminal it doesn’t work because it does a ^C. How can I get this to work so it also allows me to do COPY/PASTE using the Command key in the Terminal program? Thanks!

    • dgraziotin Sep 7, 2012 Reply

      The ^C you see is what should happen if the mapping has been successful. CTRL+C (or ^C) in a terminal is for sending a SIGINT signal to the active program (i.e., to kill it).
      This behavior is the same under OS X and GNU/Linux. However, Apple Computers have both the CTRL and the CMD keys. That is why you can have this very convenient COPY/PASTE thing in the Terminal program.
      I do not think that this is implemented in any GNU/Linux desktop environment. Try to follow the instructions posted here. They may work for you.

    • Darcy Oct 1, 2012 Reply

      Edward – can you tell me where that option is / which keyboard layout I can find it in? That’s exactly what I’m looking for!

  • John Kim Oct 18, 2012 Reply

    Brilliant post! I think it proved very useful for me in making more out of keyboard functionality. Next time, you should post on mouse gesture functionality on the mac.

    Anyway, the trick worked great. But although my left cmd button works, the right cmd button doesn’t. How can I solve this? Thanks.

    • dgraziotin Oct 19, 2012 Reply

      Hello John, it works for me with both CMD keys.
      Can you double check if the the .Xmodmap files contains these two lines?

  • luisca Oct 23, 2012 Reply

    I had this working for a long time, but now Quantal Quetzal do not seem to load .Xmodmap on login and I had to load the file manually on the command line. Further, sometimes after suspend/resume I lost the configuration (not always) and have to run the command again. Any ideas?

    • dgraziotin Oct 23, 2012 Reply

      That is rather strange. I have upgraded to Quanta Quetzal since two days and everything still works fine.
      Are you sure .Xmodmap isn’t loaded twice instead?

  • marcomau Nov 26, 2012 Reply

    After many unsuccessful experiences, finally this worked.
    Thanks man.

  • wouter92 Nov 30, 2012 Reply

    For me the .Xmodmap file is not loaded when I restart (the system logged in automatically) on Quantal.

    Also, I have this little (but really annoying) problem: cmd+s (for saving a file) does not work as expected, instead it starts echo, the workspaces overview. I tried to disable this via the compizconfig manager but no luck.

    Any ideas?

    • dgraziotin Dec 1, 2012 Reply

      There are reports on strange behaviors from other users as well. Is only cmd+s not working? Do shortcuts for copy and paste (cmd+c, cmd+v) work? That would look rather strange.

  • Daniel Cardoso May 8, 2013 Reply

    This works fine on Ubuntu 13.04. Thanks!

  • Omar Trejo Jul 11, 2013 Reply

    Thank you for posting this! Another OS X saved from frustration. 🙂

  • Mike Pearce Sep 23, 2013 Reply

    This is excellent, thanks!

    One thing I’m not sure about though, is how to get the hash key working. I found a way, which involved modifying the 3rd level key mapping in the keyboard layout, but then it messes up the above fix.

    Anyone know anything about this?

    • dgraziotin Sep 25, 2013 Reply

      I have never had this issue. Hopefully somebody can help.
      P.S. keep up the good work at moo.com. I am a very satisfied customer 🙂

  • Le Hung Thien Nov 9, 2013 Reply

    It’s no longer work on Ubuntu 13.10 🙁

  • abdulmajeed Nov 4, 2014 Reply

    I like very best.

  • Jan Vladimir Mostert Jan 12, 2015 Reply

    Works on CentOS as well, can now use my Mac Keyboard on a CentOS box and most shortcuts just works out of the box, thanks!

  • Aiswarya May 20, 2015 Reply

    Some keys are not working as expected on my dual boot ubuntu. For typing out a double quote, i need to press shift+2 , which is usually @, but the keys have reversed her.
    The shift+3 doesnt give me hashtag but this £.
    Lots of other characters are acting messed up too.
    I still can’t find backslash. The original backslash key prints ~
    Very very annoyed! please help!

    • dgraziotin May 20, 2015 Reply

      sounds like you have a wrong layout for your keyboard. For example, Italian keyboards have double quotes located at SHIFT+2. This is something you should fix before applying what is written in this post. Look for the settings of your desktop environment.

Leave a comment