I understand that you can use M-x in ansi-term's char mode by doing C-x M-x, but why can't it just be used normally? Is there some historical reason? I can use other meta commands (like M-f or M-b), why does M-x need the C-x prefix key? (Also, I understand that M-x works normally in line mode.)

  • 1
    Think about the case where you are running emacs inside ansi-term, how do you send M-x to the inner vs outer Emacs?
    – npostavs
    May 5, 2019 at 2:05
  • You could swap in any key sequence and ask the same question. For instance: How would you send C-x to the inner vs the outer Emacs? Or am I misunderstanding you?
    – edmqkk
    May 5, 2019 at 2:13
  • Yes, you can ask the question for any key, though the answer is a bit different for C-x in particular.
    – npostavs
    May 5, 2019 at 2:21

1 Answer 1


This isn't the special case that you think it is.

In general, Meta key sequences can be used in terminals (and the inferior process might have its own use for M-x), so term char mode sends these keys to the terminal.

Just like M-x itself, M-f and M-b are bound to term-send-raw-meta in term char mode. The inferior process running in the terminal is simply reacting to them in much the same way that you're used to them behaving in Emacs.

Note that if those keys were actually invoking forward-word and backward-word then the inferior process running in the terminal wouldn't know that you'd done anything (although since Emacs 26.1, the user options term-char-mode-point-at-process-mark and term-char-mode-buffer-read-only also prevent such things from creating confusion by default).

  • "The terminal line discipline (or the inferior process itself) is simply reacting to them in much the same way that you're used to them behaving in Emacs." Ah, those work because those keybindings are part of the terminal, just like you could open up any terminal (outside of Emacs) (or most any) and they'd work.
    – edmqkk
    May 5, 2019 at 2:15
  • 1
    It's really much more likely to be the process running in the terminal (e.g. a shell) than the terminal itself. Any program with more than the most trivial of user-input requirements will set the terminal to 'raw' mode (as opposed to the 'cooked' or 'canonical' mode which provides that extremely basic line-editing support), at which point any line editing is being dealt with purely by the inferior process. There's still a lot of consistency between programs, though, as so many of them use readline to handle the user input, or endeavour to be compatible with that.
    – phils
    May 5, 2019 at 2:57

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.