7

Is there a way to use the Apple command key in Emacs in the terminal? It would be nice to expand the set of easy to get at key bindings I can use.

Jake Pearson
  • 171
  • 1
  • 4
  • Related thread: [Problems with keybindings when using terminal](http://emacs.stackexchange.com/questions/1020/problems-with-keybindings-when-using-terminal). – Dan Jan 28 '15 at 14:55
  • 2
    I don't think it's possible in Terminal.app, as supplied by OS X. But if you install iTerm, you can remap the modifier keys extensively, and that opens up some possibilities. I haven't explored those possibilities, though, so I don't know for sure how much you can achieve that way. – Harald Hanche-Olsen Jan 28 '15 at 16:51
  • 1
    I'm using iTerm. I've assumed that I would need to bind command chords to sending magical hex values, but I haven't found a resource that helps me. – Jake Pearson Jan 28 '15 at 22:13

4 Answers4

5

I am using macOS Catalina, and iTerm2 3.3. This method probably works for several prior versions of macOS and iTerm2 but I have not researched it.

Note that when you remap the modifier keys below using iTerm2, will need to allow iTerm2 to "control" the OS (or take care of it when iTerm2 asks you to allow it) by checking iTerm under Security & Privacy->Accessibility. You can uncheck it after the procedure is done if that is an issue.

  1. First, remap the Left Option key in your Profile to Esc+. This allows a terminal Emacs to use the Left Option (Alt) key as Meta. To do this:

    a. In iTerm2 Preferences, click on Profiles, then on your default Profile, then click the button next to Esc+.

  2. Then, while still in Preferences click Keys->Remap Modifiers. This will allow you to switch the Command key with the Alt Key. After you do this, a terminal Emacs will use the Command key to send Meta- to Emacs.

    a. Remap left command key to Left Option.

    b. Remap left option key to Left Command.

Note that while you are using terminal Emacs in iTerm2 you will have to use the Option key to do whatever MacOS believes is mapped to the Command key, for example, to Tab between Spaces. Once you are out of iTerm2 the Command key works normally again.

Pinecone062
  • 51
  • 1
  • 5
3

The answer below tells you how to use Command as a second, redundant Meta key, which is pointless. As far as I know, it's not possible to use Command as a distinct modifier key in Terminal/iTerm---say, by mapping Command it to the Hyper key, for instance---the way you can with GUI Emacs.

incandescentman
  • 4,111
  • 16
  • 53
0

cmd-key-happy will do this for Terminal - and other applications.

0

First stem, get iTerm!

After that, (this has been answered here, so I can't take credit for it.)

Go to Bookmarks > Manage Profiles. Then select Keyboard Profiles > Global and choose Option Key as Meta.

Chris McMahan
  • 234
  • 1
  • 2