2

There are a lot of tutorials for mapping the Option key () to Meta in iTerm, e.g. here, here and here to enable readline navigation and editing (M-b to move the cursor back a word, etc.).

What I'm looking for is doing the same but with the Command key . This is possible to an extent by first setting to Esc+ and then mapping left to left and vice versa. Both are supported by iTerm2 out of the box (version 3.4).

The drawback of this is that now

  1. you can't use ⌘-TAB to toggle/cycle OS applications anymore (you have to use ⌥-TAB)
  2. with ⌥-TAB, toggling applications works but you can't hold and cycle through open applications with TAB anymore

Emacs on macOS is somehow capable of supporting both readline shortcuts with and normal ⌘-TAB behavior.

I've looked at Karabiner Elements but I haven't been able to configure it to do what I want.

1
  • Did you ever get this figured out @malana? I would really like to get a normal linux-esqu dev environment up when I ssh.
    – zachaysan
    Jul 11, 2022 at 20:07

1 Answer 1

1

I just recently found this answer myself. Leaving what I've got here for future readers who also don't realize that the answer is in the iTerm2 documentation! :D

Check the docs for the section titled "Swap Cmd and Option". The relevant text reads:

"iTerm2 allows you to remap modifiers. You have separate control over left and right command and option keys. One common need is to exchange cmd and option. To do this, go to Preferences > Keys. Set Left option key to Left command key and Left command key to Left option key (and do the same for Right command and Right option if you please). You can add exceptions if you don't want certain combinations to be remapped (for example, cmd-tab) by adding a new global shortcut with the action "Do Not Remap" and the keystroke of the (unremapped) key you wish to keep unaffected by modifier remapping."

It took me a bit to realize that even though the docs read "global shortcut", the "Shortcuts" section of the preferences is not the right place to go to set the setting needed. You'll want to head to Preferences > Keys > Key Bindings, and add a shortcut for ⌘⇥ (cmd-tab), with the action "Do Not Remap Modifiers".

This works for me in iTerm 3.4.20 / Ventura 13.4.1 / MacBook Air M1, 2020. Hope it helps.

Image of the iTerm2 "Preferences > Keys > Key Bindings" settings

1
  • 1
    It's worth noting that you have to pick the action first otherwise cmd-tab will keep changing the application. If you chose the action "Do Not Remap" first iTerm will disable the application changing and you can add the shortcut normally.
    – afrosteve
    Oct 10, 2023 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .