Making iTerm to translate 'meta-key' in the same way as in other OSes
Solution 1
- Open "Preferences" (⌘,) ->
Profiles
->Keys
->General
tab. - Set
Left Option key:
to act asEsc+
.
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
worked for me as well in irssi.
Solution 4
For iTerm2 users this answer just partially solves the problem.
Cmd+.,
Profiles
,Keys
and chooseLeft option Key acts as: +Esc
.
In addition to that, you have to go to Preferences (Cmd+,) ➔ Profiles ➔ Keys and in the Key Mappings find these Key Combination's: and
. Double click on each mapping and change their Action and Esc+ to the following:
Solution 5
Go to your iTerm preferences select "profiles" then "key" and change your presets in "Natural Text Editing"
It should work immediately after.
It works with iTerm version 3.3.12
Related videos on Youtube
![fujy](https://i.stack.imgur.com/kCade.png?s=256&g=1)
fujy
Updated on May 12, 2022Comments
-
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 over 15 yearsAfter messing with this issue for a while and cannot figure out a solution. I gave up and switched to Terminal now.
-
holms over 13 yearsdon't forget that iterm2 already exists and everything is fine in there=)
-
jv-dev about 3 yearsEven 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 over 15 yearsI 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 over 15 yearsThank 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 about 15 yearsIt 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 almost 14 yearsI had to change the xterm (OS X) entry rather than global, but it is working now.
-
fujy over 13 yearsHmm. 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 over 13 yearsI 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 over 10 yearsPreferences, 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 over 10 yearsin iTerm2 this worked only after I re-defined the Profile Shortcut Keys for
alt
+->
andalt
+<-
to Send Escape Sequence +f
/b
respectively. -
Steve Buzonas over 10 yearsMay be a new feature since this answer, but you can map a Global Key Shortcut to send
Ctrl-w
whenOpt-Backspace
is pressed. -
Skurpi about 10 yearsI had to open a new iterm session for it to kick in
-
Krzysztof Wende over 8 years@SridharRatnakumar Works for iTerm too
-
fujy almost 7 yearsWith iTerm 2 this seems to be the recommended option.
-
grego over 6 yearsFor 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 about 6 yearsI had to quit iTerm and reopen it to get this answer work
-
TheJavaGuy-Ivan Milosavljević about 5 yearsExcellent, this also works in the combination of iTerm2 + tmux
-
LeOn - Han Li over 4 yearsThis is really helpful. Thanks a lot bro!
-
dresh over 3 yearsI used Terminal.app compatibility and it worked.
-
jv-dev about 3 yearsNote:
Cmd+.
should beCmd+,
, the preferences hotkey for iTerm is different. -
nicolas over 2 yearsfor some reason I have to press CMD + ALT + -> .... in my app with that..
-
Nick D over 2 years@nicolas this thread is for macos