Remapping Macbook Pro Keys for Emacs Use


Background:

I recently took the $$$ plunge and got a fancy new 15″ Macbook Pro to replace my 5-year old ASUS laptop. Though I’m not too fond of Apple’s business model, I just couldn’t seem to find (hardware wise) a more quality built and ascetically pleasing laptop than a Macbook Pro. After 6 years straight of using Linux as my main OS (I despise Windows), I’m now learning my way around OS X for the first time. Having never used a Mac before, everything about OS X’s GUI is new to me.

Once I open a terminal though (thankfully there is one!), I start to feel more at home… except, I do not like the default placement of the ctrl / alt / command keys! Fortunately, after a few days of trying various programs and experimenting with settings, I’ve found a solution that works for me – without having to change system-wide settings.

 

My Emacs Requirements

While I’m a late-comer to adopting Emacs, I’ve been using it as my editor of choice for the past year, and am forever hooked. Since I’ve started learning Emacs, I’ve gotten used to the Option key = Ctrl key and the Command key = Alt/Meta key. So, it came as a huge annoyance to find that on my new Macbook, THERE IS NO RIGHT CONTROL KEY! Ah, I refuse to re-learn all my emacs muscle memory!

Goal: Option-->Ctrl | Command-->Meta

 

Configuring Emacs Key Bindings

Emacs can run as a standalone GUI, or within a terminal. The following are my workarounds to regain my famailar key mappings for each case.

Aquamacs

Aquamacs is a great standalone Emacs editor for OS X, and remapping its keys is pretty easy: simply add the following two lines to your .emacs file.

(setq mac-option-modifier 'control)
(setq mac-command-modifier 'meta)

iTerm2

Using custom emacs keybindings inside a terminal was a bit more tricky to figure out. Fortunately, I found iTerm2 is a nice Terminal replacement in OS X, and is very customizable. The following are screenshots of the settings to change:

As seen above:
In the Profiles > Keys screen:
* set left option as +esc
In Preferences > Keys screen:
* right option as control
* right command as left option

 

Wrapping up

Even with the Option and Command keys mapped to the “right” keys, the placement of the Macbook Pro’s Option key is not suitable for little (pinky) finger use. The placement shifts the ctrl key duty to my ring finger, but with the two keys now acting how I expect, this change isn’t too hard to get used to. So far, I’m happy I decided to go with a Macbook, as it is indeed a major upgrade from my old ASUS laptop!

 

Update (09/19/11):

Window placement

Shift-It is an incredible open-source utility for Mac OS X that mimics the window placement functionality found in Compiz on Ubuntu. The ability to move windows around using the arrow keys was something I felt was missing, until now!

 


5 thoughts on “Remapping Macbook Pro Keys for Emacs Use”

  1. Thanks Chris. I didn’t use your solution but it helped me find one option in default Terminal program that Mac OS X provides. The option is available as a check box in “Terminal –> Preferences –> Settings –> Keyboad”. Simply check the “Use option as meta key” box and your option key starts behaving as the usual alt key.

    But the placement of control and option keys is not convenient for Emacs users 🙁

  2. Hi Chris,

    Thank you very much for this post. I am in a very similar situation as you were – replacing my Asus (with Debian) with a Mac. Being a seasoned Emacs user I found it difficult to adapt to the modifier key placement on the Macbook Pro. Your tips, especially the remapping in Emacs came as a great effort-saver for me.

    Thanks once again!

  3. The app Karabiner has been an awesome solution for me. I’ve set my capslock up so that while used in a combo it acts as control, and when tapped acts as meta. Perfect for emacs and vim. Though the GUI version of Emacs can be setup to use the Command key as meta, which feels a bit better. It also gives you system wide Emacs key bindings. Some exist by default on OSX, but Karabiner provides many more, such as using C-PNFB to move around. Even works for scrolling in a browser.

Leave a Reply