No one was able to answer Rich Collins's question:

I am very frustrated with iterm on OS X. I love many of the features but I keep having issue with the wrong characters being sent to the shell. For instance, Meta-Backspace works fine in bash locally, but does not work remotely. It also does not work in my postgres shell or my irb (Ruby) shell.

People succeed in answering Rich Collins's questions 37% of the time (32 successes in 86 attempts).

Answers by: Aurelius | awt

Aurelius's Answer:

Reply by Aurelius 625 days ago

You need to set the TERM environment variable correctly. The exact value needed depends on the particular version of iTerm you are using and the capabilities of the system you are logged in to.

For the latest version of iTerm available as of 12/9/06, I have found that

export TERM=xterm

works well on remote Linux systems. Most have TERM=linux by default, which uses some weird extensions that iTerm doesn't support.

You can also try

export TERM=ansi
export TERM=vt220
export TERM=vt100

depending on the specific capabilities of the remote terminal.

That should do it for you. If you want to get really into it, you can remap the effect of keys with the "stty" program (see "man stty" for details), but that shouldn't be necessary on modern systems if you experiment with the various TERM settings available on your particular remote system until you find the correct one.

When you do get the correct one, you can put it in your ~/.bashrc (or equivalent file if you use some other shell besides bash) to run it automatically every time you log in to that machine.

Hope this helps,
A.

Reply by Aurelius 625 days ago

(The newlines didn't carry over in that sequence of "export"s. There hsould be just one export per line:


export TERM=ansi

export TERM=vt220

export TERM=vt100

Oh, make sure you're using the current version of iTerm, too.
Cheers.

Reply by Rich Collins 625 days ago

The thing is, this happens locally with irb (the ruby interpreter shell) as well as remotely. Although the characters that appear locally are different than the ones I see remotely. I did try those terminal emulators with no luck.

Reply by Aurelius 625 days ago

Ahh, ok. Maybe the issue is with the Mac's idea of the Meta key rather than the term layout. Have you tried Alt/Option as Meta?

Locally, I'm using TERM=linux with iTerm 0.9.4, irb 0.9.5 (ruby 1.8.4, fwiw).
I have a PC USB keyboard plugged into my MacBook Pro, and the Alt key functions as Meta. On the Mac keyboard, Alt/Option functions as Meta. In both cases, Meta-Backspace works fine in irb.

I found that when I upgraded to iTerm 0.9.4, the arrow keys stopped working in text-mode Emacs when ssh'ed into a remote Linux box with TERM=linux (but worked fine at the shell prompt.) Setting TERM=xterm on the remote box fixed it. (Strangely, TERM=linux still works fine locally on my Mac.)

I came from years of using a Linux desktop system, and the location of "alt" on the Mac keyboard was a source of immense frustration for me when I bought my MacBook. AquaMacs has an option to use Command as Meta, but iTerm does not. (There is an outstanding feature request at http://sourceforge.net/tracker/index.php?func=detail&aid=707143&group_id=67789&atid=518976 for "command as meta key".) The PC keyboard has the keys in the "right" places, so it is only an issue when I'm out of the office. (The Windows key functions as Command.)

System Preferences -> Keyboard and Mouse -> Keyboard -> Modifier keys lets you swap the meanings of the metakeys, if you want to semipermanently move things around.

Reply by Rich Collins 625 days ago

Actually I am using option / alt as the meta key. It works in the bash shell locally in iterm, but not in irb / other remote shells.