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.
source to share
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-?])
source to share