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

前端 未结 8 845
广开言路
广开言路 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条回答
  •  离开以前
    2021-02-04 06:59

    Note: The issue isn't limited to Linux, it exists on Windows (and presumably Mac) as well. Read the other (non stack-overflow) source of all knowledge: Wikipedia on Carriage Return.

    If you want to rebind C-m, be sure to all bind otherwise you run the risk of no longer being able to use the Enter/Return key. Also, in a terminal, Emacs cannot distinguish between the two (C-m and ).

    In a plain Emacs, the Enter/Return key is bound to , which is (by default) translated to RET (same thing as C-m). If you only rebound the C-m, you'd also be affecting the Enter/Return key.

    Try C-h k and you'll see

    RET (translated from )

    So, rebind both in the appropriate keymap to make sure you get the behavior you want.

    It might be instructive to play with the following code:

    (defun my-return ()
      (interactive)
      (message "return"))
    (defun my-ret ()
      (interactive)
      (message "RET"))
    (defun my-c-m ()
      (interactive)
      (message "C-m"))
    (global-set-key (kbd "") 'my-return)
    (global-set-key (kbd "C-m") 'my-c-m)
    (global-set-key (kbd "RET") 'my-ret)
    

    Put that in your *scratch* buffer and press C-j after each line (to evaluate the sexp). Then play with the Enter/Return keys and C-m.

提交回复
热议问题