Passing alt/opt key sequence over ssh to remote host with iTerm

itermkeyboardsshterminaltmux

Just learning the ropes of my new MacBook Pro.

I have a linux workstation at the office that I use to host a number of tmux sessions, which represent whatever Im working on at a given time.

If out and about I will ssh into this workstation using iterm2 and tmux attach -t to any given session.
In tmux I have certain keys bound to certain actions, specifically, I have the movement between panes bound to Alt+[HJKL] to move in a given direction.

I'll bet you can see the problem! Mac therefore No Alt key!
Is there a way I can map the apple key (or some other key) to be recognised as Alt when ssh'd to this host? or even globally if its not a per host setting?

Thanks in advance

Best Answer

A terminal connection, such as created by SSH, basically transfers characters, not keystrokes. There are some exceptions to this, such as the "return" key and CTRL+letter combinations, because they have been in use since time immemorial and have their own character codes, and some keys like the arrow keys are handled by sending multi-character sequences, but more "modern" inventions, such as ALT combinations (which did not exist on the 1970:s-era terminals of which modern terminal windows are the descendants) are simply not handled.

Some terminal programs provide various work-arounds for this. One such work-around is setting the eighth bit in the character code when the ALT key is pressed, but this breaks down if you use some other character encoding than 7-bit ASCII. A more sensible workaround is to prefix "alted" letters with an ESC character, so that typing Alt-A is the same as typing Escape and then A.

So you need to figure out which of these conventions tmux expects, and then configure iTerm2 to follow that convention. I don't use iTerm2 myself, but it seems to have "Meta" (set eighth bit) and "Esc+" options under "Keys" in the settings window.