How to bind an Emacs key to delete a whole word back like the same in the shell?

I just started learning Linux and Emacs. It was nice to have the same key bindings both in Emacs and in the shell (bash / tcsh) for the most commonly used cursor movements, so I don't have to consciously think about which one I should use. Even worse, use the wrong command and undo the error. However, there were two exceptions.

A commonly used command was the equivalent of backspace, removes the back character. It was in the shell C-h

. I got the same behavior in Emacs thanks to this advice from Janos, who probably felt the same way. http://www.math.rutgers.edu/~komlos/emacs.htm

Now the mistake I often make in Emacs is trying to delete words backwards with a command M-C-h

, just like in a shell.

Can someone please provide a binding that will cause Emacs to delete words backwards with "MCh"? Currently, this command selects all text in the buffer, which is quite useful ( C-a

on Windows), but not so often used to delete words back.

Moreover, any binding to replace the current binding M-h

(from the link above) to help would be appreciated.

Thank,

Elan.

+3


source to share


3 answers


Below binds CM h to the kill-backward. You can put it in a .emacs file.



(global-set-key (kbd "C-M-h") 'backward-kill-word)

      

+3


source


You can use M-<backspace>

in terminal and emacs to strip back the word.



+3


source


Your best bet is to use key translation, so it C-M-hworks exactly the same as it M-backspacewould in any minor mode (regardless of whether M-backspace is bound to backward-kill-word

or not).

;; bind C-h to <backspace>
(define-key key-translation-map [?\C-h] [?\C-?])
;; bind C-M-h to M-<backspace>
(define-key key-translation-map [?\C-\M-h] [?\C-\M-?])

      

+1


source







All Articles