Apple - OS X Terminal: "backward delete word" works only with C-M-h
Settings in DefaultKeyBinding.dict don't apply to the shell views in Terminal or iTerm 2.
You can make M-h
delete a word backward by adding this to ~/.inputrc
"\eh": backward-kill-word
M-h
is bound to mark-paragraph
by default in Emacs though.
If others search for how to make ⌥⌫ delete a word backward, just enable using option as a meta key:
- In Terminal, check Settings > (your profile) > Keyboard > Use option as meta key
- In iTerm 2, set the option keys to act as "+ Esc" in Profiles > (your profile) > Keys
If others search for how to make ⌥⌦ delete a word forward, you can make it insert \ed
:
⌥⌦ inserts \e(
by default in Terminal and \e[3~
in iTerm 2, so you could also add "\e(": kill-word
or "\e[3~": kill-word
to ~/.inputrc
.
Almost all terminal use emacs hotkeys to manipulate text (see readline keyboard shortcuts), and in emacs, you use backward-kill-word
(meta-delete) to delete the previous word.
And, in emacs, meta-<KEY>
(key composition) equals to escape <KEY>
(key chord), so in this case, you can use ESCAPE DEL to delete the previous word.