views:

3479

answers:

9

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.

A: 

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,

A: 

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

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

Kyle Cronin
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.
ejel
+10  A: 

Try Option Key as +Esc

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

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.
ejel
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.
Dominic Cooney
This worked for me as well but doesn't make any sense
scottschulthess
+3  A: 

I couldn't get the Alt key working either but there is a workaround that makes it at least function for word navigation via the cursor keys:

Skip to Next or Previous Word in iTerm Using Alt / Option + Left or Right Arrow Keys

nyenyec
+2  A: 

Opiton key as +Esc worked for me as well in irssi.

+5  A: 

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.

Dag Høidahl
Optioin Key as +Esc worked for me.
Sridhar Ratnakumar
I had to change the xterm (OS X) entry rather than global, but it is working now.
Jason Axelson
+1  A: 

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

+1  A: 

...and if you want to preserve your Option key as modifier (say, you use a keyboard layout that has some useful national characters bound as Opt+$key), there's a patch for iTerm to give you exactly that here

yacoob
A: 

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

holms