Making iTerm to translate 'meta-key' in the same way as in other OSes

91,038

Solution 1

  1. Open "Preferences" (,) -> Profiles -> Keys -> General tab.
  2. Set Left Option key: to act as Esc+.

Works for me in Emacs, though I'm not sure if it will have any other undesirable effects.

Solution 2

Go to Bookmarks > Manage Profiles. Then select Keyboard Profiles > Global and choose Option Key as Meta. This works for me in version 0.9.6.1201.

Solution 3

In Menu bar Iterm2 => Preferences => Profiles choose the keys tab and select

left Option key act as +Esc

enter image description here

worked for me as well in irssi.

Solution 4

For iTerm2 users this answer just partially solves the problem.

Cmd+., Profiles, Keys and choose Left option Key acts as: +Esc.

In addition to that, you have to go to Preferences (Cmd+,) ➔ ProfilesKeys and in the Key Mappings find these Key Combination's: enter image description here and enter image description here. Double click on each mapping and change their Action and Esc+ to the following:

enter image description here

enter image description here

Solution 5

Go to your iTerm preferences select "profiles" then "key" and change your presets in "Natural Text Editing"

iTerm Preferences

It should work immediately after.

It works with iTerm version 3.3.12

Share:
91,038

Related videos on Youtube

fujy
Author by

fujy

Updated on May 12, 2022

Comments

  • fujy
    fujy about 2 years

    In bash shell with emacs key-binding, you can use key combination like M-f, M-b to move one word forward or backward on the shell prompt respectively. Usually, the meta key is mapped to Alt key on Windows and Linux. However, in iTerm, I could not find a way to map this meta key to either Option or Command key on my MacBook Pro.

    It seems that in OS X, the meta key is by default mapped to ESC key. So you can use ESC-f, ESC-b on iTerm. However, ESC key is apparently not practical to use. In addition, iTerm does have option that allow you to modifier mapping for the meta key (Bookmarks > Profiles > Keyboard Profiles > Global > Option Key as...), this setting does not seem to work at all.

    Therefore, if anyone know what is the solution to this problem, please let me know.

    I have upgraded to the latest release, 0.9.6.1012, and this behavior is still persist.

    Edit: Some clarification to my question. The key-binding I'm talking about is for bash shell, not in emacs. It just happens that, by default, bash shell also use the same key-binding as emacs.

    • fujy
      fujy over 15 years
      After messing with this issue for a while and cannot figure out a solution. I gave up and switched to Terminal now.
    • holms
      holms over 13 years
      don't forget that iterm2 already exists and everything is fine in there=)
    • jv-dev
      jv-dev about 3 years
      Even with iterm2, from a fresh install 2021-May, on a Mac one still needs to remap left/right option to act as "+Esc" rather than "Normal"
  • fujy
    fujy over 15 years
    I did try Option Key as... with all choices but none of them works for me in bash shell. It only shows "?" every time I press the meta key combination.
  • fujy
    fujy over 15 years
    Thank you. I am aware that I can do that in Terminal. I just want to achieve the same result in iTerm. By the way, what I'm looking for is the key-binding in bash shell, not in emacs. It just happens that bash shell also uses emacs key binding.
  • Dominic Cooney
    Dominic Cooney about 15 years
    It looks like your input language has to be U.S. for the +ESC option to work. +ESC didn't work for me when I had the Japanese/Romaji input method selected, but it started to work once I switched the input language to U.S.
  • Jason Axelson
    Jason Axelson almost 14 years
    I had to change the xterm (OS X) entry rather than global, but it is working now.
  • fujy
    fujy over 13 years
    Hmm. The setting seems to be broken on my machine with these two versions as well. However, the latest 0.9.6.20090928 and 0.10 work as expected though.
  • fujy
    fujy over 13 years
    I don't know why on my machine the setting is broken on 0.9.6.1201 and several other builds I tried. It works, however, with the latest 0.9.6 build and 0.10 though. So it shouldn't be an issue now.
  • cgl
    cgl over 10 years
    Preferences, Profile, Keys and choose Left option Key acts as: +Esc. Then you will have both left option key AND Esc key as meta key. That is what happened in my case.
  • Amir Nissim
    Amir Nissim over 10 years
    in iTerm2 this worked only after I re-defined the Profile Shortcut Keys for alt+-> and alt+<- to Send Escape Sequence + f/b respectively.
  • Steve Buzonas
    Steve Buzonas over 10 years
    May be a new feature since this answer, but you can map a Global Key Shortcut to send Ctrl-w when Opt-Backspace is pressed.
  • Skurpi
    Skurpi about 10 years
    I had to open a new iterm session for it to kick in
  • Krzysztof Wende
    Krzysztof Wende over 8 years
    @SridharRatnakumar Works for iTerm too
  • fujy
    fujy almost 7 years
    With iTerm 2 this seems to be the recommended option.
  • grego
    grego over 6 years
    For my external keyboard I had to set both left and right option keys to use Esc+, even though I was using the left option key it would still print weird characters. This might happen because I use the Keyboard Modifiers option in Mac Keyboard settings to change the keys.
  • Joyoyoyoyoyo
    Joyoyoyoyoyo about 6 years
    I had to quit iTerm and reopen it to get this answer work
  • TheJavaGuy-Ivan Milosavljević
    TheJavaGuy-Ivan Milosavljević about 5 years
    Excellent, this also works in the combination of iTerm2 + tmux
  • LeOn - Han Li
    LeOn - Han Li over 4 years
    This is really helpful. Thanks a lot bro!
  • dresh
    dresh over 3 years
    I used Terminal.app compatibility and it worked.
  • jv-dev
    jv-dev about 3 years
    Note: Cmd+. should be Cmd+,, the preferences hotkey for iTerm is different.
  • nicolas
    nicolas over 2 years
    for some reason I have to press CMD + ALT + -> .... in my app with that..
  • Nick D
    Nick D over 2 years
    @nicolas this thread is for macos