Bash: can I set Ctrl-Backspace to delete the word backward?
Why not just use Alt+Backspace or Ctrl+W that are already mapped in most terminals. Not sure about Console. Xmodmap (man xmodmap) may be used to remap other custom keys as well. (Paradoxically, xmodmap can't remap Backspace very well because the terminal overrides the mappings, but it works well with most keys...).
I found this thread via google, but the answer wasn't what I wanted to hear. So I played around:
On my terminal, normal backspace sends ^H
, while ctrl+backspace sends ^?
.
So it should simple be a case of rebinding ^?
to delete a word, which by default is available via Ctrl+W.
First (unsuccessful try):
$ bind -P | grep 'C-w'
unix-word-rubout can be found on "\C-w".
So therefore this should work:
$ bind '"\C-?":unix-word-rubout'
However it does not... anyone able to explain?
Second (successful) try:
$ bind '"\C-?":"^W"'
Where the ^W
is a literal/raw ^W
(press ctrl+V then ctrl+W to make it appear).
Just edit your ~/.inputrc
(you might need to create one or copy the one in /etc/inputrc
there) so that it contains:
# Ctrl-Delete: delete next word
"\e[3;5~": shell-kill-word
# Ctrl-Backspace
"\C-H": shell-backward-kill-word
This will map also Ctrl+Delete to delete the word next to the cursor.