10

I see that this question has been asked multiple times. The solutions given there in does not seem to apply to my setup. Here is my story:

I use ubuntu 12.0.04 LTS, with xmonad (not over gnome), and use xterm for my work. I would prefer to use xterm rather than a different terminal or emacs own window. When using emacs -nw, I see that Alt is not recognized. I verified using xev that Alt is indeed getting generated. Further, if I am using rxvt, I see that Alt is getting recognized by emacs -nw. I am using evil mode (as a long time vim user, and an emacs newbee), and I would really prefer not having my escape key rebound as alt (which was the solution given in another thread). What should I do? (If it helps, Alt-x on the xterm window without emacs running generates "ø" or if I run emacs -nw -Q).

4
  • If I'm not mistaken Alt is being read as M instead.
    – Braiam
    Apr 3, 2014 at 1:27
  • I didn't understand, you mean M rather than Meta right? Why do you say that? Apr 3, 2014 at 1:38
  • Emacs Meta key. Can't you press M-x?
    – Braiam
    Apr 3, 2014 at 1:44
  • 1
    Oh, that is my problem. I expected Alt-x to generate M-x (as it does on graphical mode) but it does not do that on xterm for me. Instead it generates (ø) Apr 3, 2014 at 1:47

3 Answers 3

14

As seen in the Arch Wiki, you need to make Xterm to send the correct escaped key to the program:

If you use the Alt key for keyboard shortcuts, you will need this in your resource file:

XTerm*metaSendsEscape: true

So, just do:

echo 'XTerm*metaSendsEscape: true' >> ~/.Xresources

And restart your Xterm session.

3
  • Thanks, that worked. So, if Alt sends escape now, how does xterm handle Escape? (Escape works too, I am asking for my understanding.) Apr 3, 2014 at 2:39
  • @rahul I didn't say "Esc" escape, but escaped key press "^M"
    – Braiam
    Apr 3, 2014 at 2:40
  • 6
    instead of restarting your session you can also run xrdb -merge ~/.Xresources Mar 24, 2016 at 4:18
3

If updating ~/.Xresources doesn't work for you, do as the documentation says and update it in ~/.Xdefaults

http://frequal.com/linux/XTermMetaSendsEscape.html

1
  • This worked for me in bare X server, like with startx /usr/bin/xterm, where ~/.Xresources was ignored.
    – Ruslan
    Mar 18, 2020 at 18:33
3

There is an interesting alternative to managing your .Xdefaults / .Xresources files by providing the resource string directly as xterm command line option:

xterm -xrm 'xterm*VT100.metaSendsEscape: true'

This is handy, for example, if you have a custom alias for x-terminal-emulator anyway.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .