How to turn off alternative Enter with Ctrl+M in Linux

前端 未结 8 946
广开言路
广开言路 2021-02-04 06:37

Why is Ctrl+M bound to Enter in Ubuntu Jaunty? How to turn it off?

I\'m using Emacs and would like to bind Ctrl+M to some other command.

8条回答
  •  Happy的楠姐
    2021-02-04 07:04

    It's unclear whether the previous answers have solved this question, so here's another spin on it:

    Historically, "return" frequently meant two things: Carriage Return, and Line Feed.

    Quoting wikipedia:

    Originally, carriage return was the term for a mechanism or lever on a typewriter that would cause the cylinder on which the paper was held (the carriage) to return to the left side of the paper after a line of text had been typed, and would usually move the paper to the next line as well. Later it was used for the control character in Baudot code on a teletypewriter for end of line return to beginning of line and did not include line feed.

    Long story short, there are two ASCII codes that are relevant to end-of-line (and, therefore, potentially to the return key): CR (ASCII decimal 13, or Ctrl-m) and LF (ASCII decimal 10, or Ctrl-J).

    I think the general convention these days is for the return or enter keys to map to ASCII 13, and thus be "return" (RET in emacs messaging). But if you're running emacs from a terminal emulator, this may mean that you don't have the option of having a C-m binding that's different from RET. When I try running emacs in a terminal (GNU Emacs 23.2.1 on MacOS X in Terminal.app), and I try typing C-h c (i.e. pressing my return/enter key), I get:

    RET runs the command newline
    

    If I type, instead, C-h c C-m (i.e. holding down control and pressing M), I get:

    RET runs the command newline
    

    In other words, the exact same thing. Emacs (nor any other program run from the terminal) can't tell the difference between the two. (Knowing this can sometimes be handy -- if you're logged in to a system that maps things differently than the system you're coming from, you can type C-m or C-j to get the thing you want, depending on the way the mapping is screwed up.)

    And speaking of having the mapping screwed up, I'll just mention that there are some stty settings that can be relevant to such things: inlcr, inlcr, and igncr (these three are related to how input is processed -- there are also some output-related ones). I doubt that making stty changes is going to be useful to this particular problem, but I thought it worth mentioning.

    In the end, I think your choices are:

    1. Live with not having C-m that means anything different than return/enter

    2. Run a graphical version of emacs, instead of the terminal version. This should have access to the distinct keycodes, which the terminal emulator isn't passing along (because it's emulating a terminal, which didn't have such things in the same way as modern computers do).

提交回复
热议问题