Wednesday, December 30, 2009

How to fix xterm on cygwin when the alt-key doesn't work

Most of my keystrokes go into xterm, and from there to my shell, tcsh. (Some people use bash, which has the same problem.) Shells typically let you use emacs-like commands to edit your command-line -- for example, Control-B to move back one letter, Alt-B to move back one word; Control-F to move forward one letter, Alt-F to move forward one word. Unfortunately, some combinations of X Window server and xterm options doesn't correctly get the alt-key all the way through to the shell.

I use Cygwin under Windows, and sometimes when I type Alt-B into my xterm window, instead of going back one word, I'll see a weird control-character, like this: รข.

There are two ways I've found to fix this: one for an xterm that's already running, and one for launching future xterms without this problem.

For xterms that are already running:
  • Left-click inside the xterm
  • Hold down the Control key, then left-click and hold the left mouse button. This will bring up a context menu.
  • Scroll down to "Meta sends escape" -- it's about halfway down
  • Release the mouse button
To get future xterms to run with this option:
  • Edit the command-line you use to run xterm to include the following argument:
-xrm "xterm*VT100.metaSendsEscape: True"

Here's an example of a complete xterm command including that argument:

xterm +tb -xrm "xterm*VT100.metaSendsEscape: True"

This tells xterm it should convert "Alt-B" into a two-keystroke sequence: Escape, then B. It gets around systems where, for some reason, the keyboard-to-shell path is not 8-bit clean.

No comments:

Post a Comment