One of the major problems with using X11 to run *NIX applications on OSX is switching from using the Apple/Command/⌘ key to using the Control key as your primary modifier key.
First of all, I don’t understand why the Control key is where it is on keyboards for OS’s that use it as the primary modifier key. It is probably the least ergonomic key to use (unless you have the good fortune of using a Thinkpad, since they don’t include the Windows key). Apple, for all its missteps, gets it right by making the primary modifier key easy to press in combination with other keys. Command, Control, Apple, ⌘, whatever you call it, put it in a comfortable spot! That one detail almost prevented me from switching to something other than OSX. Seriously.
With that said, it’s no surprise that Apple puts the rarely-used-in-OSX Control key off to the far corners of the keyboard. As to why Apple doesn’t include an option to switch the Control/Command keys in the X11 preferences, I can only imagine.
Second, making this change isn’t for *NIX purists that like it the way it is. Don’t get pissed at me. I’m just trying to help Mac people enjoy the fruits of the Open Source community because I’m frustrated with Microsoft and Adobe (and even Apple). Their customers take a back seat to their interest in making money.
Let’s Get Started!
This is simple and if anything goes wrong, it’s easy to get back to where you started. Here’s the meat and potatoes:
- Start the X11 application
- In X11 go to X11 > Preferences > Input tab. Make sure that the following options are UNCHECKED:
- Follow system keyboard layout
- Enable key equivalents under X11
- Close X11 Preferences.
- Open the Terminal.app (Applications > Utilities > Terminal.app)
- Type the following in the Terminal window:
vi ~/.Xmodmap
and press Enter. This will open a file named ‘.Xmodmap’ located in your home folder ‘~/’ with the text editor program called Vi. Don’t be frightened! - Vi is run from within the Terminal, so it won’t look much different. Press ‘a’ to switch to Vi’s Insert Mode (I think the ‘a’ stands for ‘Append’) and then type in or copy/paste the following text:
! ~/.Xmodmap
clear Mod2
clear control
keycode 63 = Control_L
keycode 67 = Control_L
add control = Control_L - If you have a MacBook and want to use both the left and right ⌘ keys, use this version instead:
! ~/.Xmodmap
clear Mod2
clear control
keycode 63 = Control_L
keycode 67 = Control_L
keycode 71 = Control_L
add control = Control_L - Now press ‘esc’ or the Escape key to exit the Insert Mode and return to the Command Mode.
- Type
:wq
and press Enter. This command tells Vi to Write (think ‘Save’) the changes you made to the file and Quit Vi itself. - Type
xmodmap ~/.Xmodmap
and press Enter to complete this process. - Quit Terminal.app
- Open something in Gimpshop, Gimp, OpenOffice, Inkscape or any X11 application that you use to test if you have successfully switched to the Apple/Command key.
If you suddenly cannot get any of your X11 applications to start, you can delete the .Xmodmap text file from your home directory. To do this, open a Terminal in either the X11/terminal or the OSX Terminal.app: rm ~/.Xmodmap
and press Enter. The command rm stands for ‘Remove’. Be careful with this command. There is no ‘undo’ in the command line.
This post uses information found at //extrabright blog and The University of Illinois at Chicago’s Unix 101 pages on Vi. This is my attempt to write a more concise how-to.
Great tutorial!
Do you know how to do this the other way too?
As in, make the Control key act like the command key normally would?
There is a problem with this particular choice of .xmodmap; namely, it breaks the ` (accent grave) key. I have some need for this key in my work so I use a different .xmodmap:
remove control = Control_L Control_R
remove Mod2 = Meta_L Meta_R
keysym Meta_L = Control_L
keysym Control_L = Meta_L
keysym Meta_R = Control_R
keysym Control_R = Meta_R
add Mod2 = Meta_L Meta_R
add Control = Control_L Control_R
Thanks Gabriel. I don’t have a Mac to test this on (switched to Linux on my home machines) but this looks like it could be helpful for people with needs similar to yours.
Thanks! So much better.
Thank You!!! I have been looking forever about how to do this
my control key is broken and i needed this for inkscape
you deserve a pat on the back.
thank you so much!
Well done for sharing this. Works like a dream! I use Gimp and Inkscape and this was the one thing that was stopping me from dumping Fireworks and Photoshop.
Thank you for this!
Hello,
All work fine but one thing – when I use Notepad++, almost all Mac shortcut Command + X, Command + V etc. works except Command + C.
Any idea what can be wrong ?
Regards
Matt | Mac mini
You’re a star!
Thanks, it till works fine on my MacBook Pro OS X 10.11.1 and XQuartz 2.7.7 (xorg-server 1.15.2)
Thanks for the tip. Really annoying to use ctrl instead cmd on XQuartz. It worked like a charm.