When in shell (bash) - I want to have Ctrl-Backspace binded to "delete word backward". Is it possible?
konsole - terminal at KDE.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
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.
$ 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?
$ bind '"\C-?":"^W"'
^W is a literal/raw
^W (press ctrl+V then ctrl+W to make it appear).
There are some good answers here, but I solved it in Konsole with Settings->Edit Current Profile->Keyboard->Edit, then adding a mapping from
\x17. (I found the ASCII code for Ctrl-w using
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.
That depends on what bash sees. On regular terminal interaction, bash does not see what key modifiers you pressed, only the resulting character. Backspace is already the same as control-H, for example. Holding down shift or control makes no difference.
HOWEVER, your terminal application (xterm? cmd? Terminal? Putty? Depends on your OS) can see your keypresses, and may have a way to map the control-backspace key combination to something bash can tell apart from backspace.
Optionally add the following to ~/.inputrc to make it permanent:
Works on bash 4.3.11 in Kubuntu 14.04
Settings -> Edit current profile
[Add]button and under the
Key Combinationcolumn type
Backspace+Ctrl. In the
0x08(which is conventionally the backspace character)
Now you should be able to map that key to
# ~/.bashrc bind '"\x08":backward-kill-word'
On most terminals CTRL+W should already delete a word backwards. This works with xterm and I guess it works with konsole. CTRL+W is a standard key binding on text-based program that will work with vim in insert mode, emacs, and every shells.