Pages

2.08.2016

Emacs + OSx + iterm2 = Meta key works!

Three years ago I got a Mac laptop at work, and it was my first contact with Mac/OSx. Two of those three years I avoided using it for any meaningful work. There were weeks at a time that I didn't even carried it with me. Not so much because I didn't like it (hey, it's a Linux under the hood!) but because all my work environment was already set up in my work desktop and I'm not a fan of duplication.

Everything was well until curiosity got me (and I started working from home more frequently) so I decided to get out of the comfort zone and really try to use it. It's been a year already. I can say that the most painful thing has been getting the Meta key in Emacs to work correctly. I was able to avoid finding a solution for a year (boy, am I lazy!) and settled with half-solutions like using Esc instead, but now it is inevitable to find one since I bought a personal laptop recently. 

I tried first some of the stuff here: https://www.emacswiki.org/emacs/MetaKeyProblems
The first more or less useful set up was to swap modifier keys in System Preferences but that changed the whole layout for other applications and it meant strain injury for apps that weren't emacs. 

Finally, this is the stuff that worked:
  • In System preferences: 
    • Keyboard > Modifier keys > Reset all to default
    • Spotlight > Uncheck "Spotlight menu keyboard shortcut" or set it to something else 
  • Install and launch iterm2
  • In the iterm menu > Preferences > Keys > Remap modifier keys, set:
    • Left command key: Control
    • Right command key: Control
    • Leave the rest on default
  • Now in iterm menu > Preferences > Profiles, set:
    • Left option key acts as: +Esc
    • Right option key acts as: +Esc
  • Profit!
Happy emacs!

No comments: