I am using MobaXterm on Windows 10 to access a remote Linux machine running RHEL 7.5, but this is generally applicable to Emacs (same things happen with PuTTY, for example). My connection is weak and I'm trying avoid using Moba's X server, so I'm running Emacs in the console by starting it with -nw.

However, that messes up my right Alt key (plus many other things, see footnote). When I'm running Emacs through an X server, the keyboard is appropriately sending Meta for both Alt keys. In the console, the left works okay but the right doesn't register at all (so Alt-< just transmits a "<").

I've discovered that I need to modify the keymap. Things like these answers/pages/posts explain somewhat about it: one, two.

The problem with the guidance therein is that I am not root, nor will I ever be. I don't have permission to access /dev/console, so both dumpkeys and loadkeys barf at me. The answers at this related question are for Windows and Fedora.

Is it possible to use something other than a dumb Linux terminal when starting Emacs with -nw?


Can I fix my keymap without modifying the operating system's keymap?

(I say dumb because from inside Emacs if I run (getenv "TERM") the result is dumb, although that's actually true even when I try it from an X Emacs instance).

(footnote) Ctrl is messed up on both sides. For some reason describe-key says that Ctrl-/ is sending C-_, and C-h does nothing but backspace.

1 Answer 1


The information in the questions you linked to isn’t actually relevant, because it only applies when you are using the “Linux console”, which is very different from using a terminal emulator. You are using a terminal emulator to connect to the machine using the ssh protocol.

Your terminal emulator, whether it is PuTTY or anything else, probably emulates something similar to a VT220. Those terminals were very popular, but they did not support many modifier keys. The control key, when used with the characters “@” through “_” generates the 32 control characters that make up the first part of the ASCII character set. This means that backspace and C-h are truly indistinguishable; both send the same 0x08 Backspace character. The alt key prepends an escape character to whatever you type, so typing Alt-a sends two bytes, first 0x1B Escape then 0x61 a. Combinations involving both control and alt were never supported. Control and shift used together also send the same control characters, so you cannot distinguish between C-a and C-S-a (aka C-A).

GUI applications, on the other hand, get keyboard events that detail exactly what key was pressed (or unpressed), and the OS helps out by keeping track of what modifier keys where held down simultaneously.

If you were using XTerm then I would suggest using the modifyOtherKeys option. This tells XTerm to do something that no terminal ever used to do and send a long escape sequence for any key that can’t be sent using a shorter one. These escape sequences contain information about exactly what modifier keys were in use at the time, much like the keyboard events a GUI application gets. Emacs is already listening for these escape sequences, so it should just work once you turn it on.

Perhaps your terminal emulator has a similar option, but I will leave it to you to look in the documentation. You might also browse the many, many similar questions and answers here on StackExchange; perhaps one of them has information about your terminal emulator.


Oh, and I should also point out that you checked the value of the TERM environment variable incorrectly. You should check the value in the shell before you run Emacs. Emacs uses that value to determine how to interact with your terminal, but then during startup it overwrites it with the value “dumb” so that when you run M-x shell or M-x eshell or any other program through features such as comint-mode, those programs will know that they should not try to use escape sequences to get color and so on. After all, they’re running inside Emacs, not a terminal or a terminal emulator.

  • Thank you so much for the great info! Thanks for the clarification of how Emacs overwrites the TERM variable (good to know), but I'm still confused - when I check the TERM variable from MobaXterm the result is, as expected 'xterm'. But if I launch emacs -nw from that, I get the behavior I mentioned. I was assuming that emacs somehow launches its process into a standard Linux terminal much like Windows programs are really running on top of DOS (or at least they used to), why would a VT220 come in to it?
    – Ajean
    Commented Oct 6, 2022 at 16:30
  • 1
    Ooo, okay I just tried launching a spanking new xterm from Moba's main prompt, and running emacs -nw from there. That makes Alt work properly. So looks like you are right its the terminal emulator's fault...
    – Ajean
    Commented Oct 6, 2022 at 16:36
  • 1
    You know that “DOS” window that opens up when you run and old DOS program? That’s a terminal emulator. It just emulates a really weird terminal–like interface that was never actually created by a terminal. Terminals are from the mainframe/minicomputer era, while DOS was an OS for a microcomputer. Microcomputers from the time when DOS was written had essentially the same computing power as the terminals that were attached to the mainframes and minicomputers of the previous era.
    – db48x
    Commented Oct 6, 2022 at 19:38
  • Hehe, that is going back a ways, definitely! Sigh, one would think that modern software would not be so beholden to old stuff. I also found out (different thread) that MobaXterm uses PuTTY under the hood, at least to some degree, so the fact that the PuTTY behavior is the same now makes sense.
    – Ajean
    Commented Oct 6, 2022 at 20:16
  • 1
    It is a problem with PuTTY, it’s just not related to that particular wishlist item. Screen won’t help you either; to get proper key events you have to be a gui program, and screen is not a gui program. PuTTY puts “xterm” into the TERM variable because it wants to pretend that it is compatible with xterm, but that compatibility is incomplete. modified-keys and key-mapping look relevant, after a very quick search.
    – db48x
    Commented Oct 7, 2022 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.