4

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.

  • Related thread: Problems with keybindings when using terminal. – Dan Jan 28 '15 at 14:55
  • 1
    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
  • 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
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.

| improve this answer | |
1

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.

| improve this answer | |
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.

| improve this answer | |
0

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.