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

MacosCommand LineKeyboard Shortcuts

Macos Problem Overview


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.

Macos Solutions


Solution 1 - Macos

  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 - Macos

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 - Macos

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 - Macos

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 - Macos

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

Solution 6 - Macos

Going all zombie resurrection here, but for sake of posterity --

This post got it working as you desire for me, for M-b and M-f, while keeping 'Option Key as Meta' set so you don't sacrifice a modifier (I have vim mappings using meta, personally).

In summary, in your Global Keyboard Profile, add two new mappings with settings:

  1. Key as hex code, value of 62 for b, 66 for f (man ascii)
  2. Modifier as Option
  3. Action as send escape sequence, value b or f

The only thing I still miss from Terminal.app is Opt-Backspace to delete by word. There are other workarounds for that, but I'm just trying to train myself to use Ctrl-w.

Solution 7 - Macos

It's easier in iTerm2. Go to preferences->bookmark->keyboard and select Option sends +ESC. In iTerm2 you can configure the left and right option keys separately, so remember to change both if that's what you want. Link for iTerm2: http://sites.google.com/site/iterm2home/

Solution 8 - Macos

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

Works in iTerm Build 0.9.5.0611 & Build 0.9.6.20090415

Solution 9 - Macos

I found some solution on stackoverflow also, just go to keyboard profile and in "Global" change "Option key as" +ESC

that works for me perfectly =) btw some iterm patch exists also look here: http://www.emacswiki.org/emacs/EmacsForMacOS

Solution 10 - Macos

I don't know about iTerm, but you can do this in Terminal. Instructions can be found here:

https://stackoverflow.com/questions/162896/emacs-on-mac-os-x-leopard-key-bindings#162907

Solution 11 - Macos

Here is what worked for me: Bookmarks > Manage Profiles > Keyboard Profiles > Global/xterm > Option Key as +Esc. With this, I can use Option+Enter in Midnight Commander and the currently selected file/directory name shows up in the command string, as it should. Option Key as Meta did not work for me. My build of iTerm is 0.10.

Solution 12 - Macos

I was struggling with Meta + Left or Meta + Right. The context was for keystroke in Emacs utilized in an iTerm2 session.

I tried Esc+ and Meta for the left Option key with no luck. I tried with and with out the hex mappings. No luck.

But then I tried "Report modifiers using CSI u". (Documentation here). That allowed me to use the meta + Left and meta + right keys in Emacs, which is the behavior I have on my Linux machine.

Solution 13 - Macos

Try "export LANG=C". I'm not emacs expert, but I found this enables emacs on OS X to recognize the Option key as the Meta key in iTerm,

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionejelView Question on Stackoverflow
Solution 1 - MacosSam KeshavarziView Answer on Stackoverflow
Solution 2 - MacosDag HøidahlView Answer on Stackoverflow
Solution 3 - MacosHatem NassratView Answer on Stackoverflow
Solution 4 - MacosNick DView Answer on Stackoverflow
Solution 5 - MacosKillianGDKView Answer on Stackoverflow
Solution 6 - MacoschesView Answer on Stackoverflow
Solution 7 - MacosGeorgeView Answer on Stackoverflow
Solution 8 - MacosmnbView Answer on Stackoverflow
Solution 9 - MacosholmsView Answer on Stackoverflow
Solution 10 - MacosKyle CroninView Answer on Stackoverflow
Solution 11 - Macosmikhail_bView Answer on Stackoverflow
Solution 12 - MacosTony KnappView Answer on Stackoverflow
Solution 13 - MacosfabianView Answer on Stackoverflow