When in shell (bash) - I want to have Ctrl-Backspace binded to "delete word backward". Is it possible?


I'm using konsole - terminal at KDE.

  • 2
    The question is straight forward, no complains about that. I just want to comment that it is often worth a lot to facilitate "standard" key bindings that already exist in many applications, instead of customizing away for no real gain and the certainty of never seeing the behaviour on foreign systems. Ctrl+w is what you should get accustomed to, imho. Mar 20 '12 at 15:45
  • @ Daniel Andersson: or alternatively - You can develop a way to transfer Your settings to the foreign machine.
    – Adobe
    Mar 20 '12 at 17:39
  • Sharing dotfiles is a solved problem, but it doesn't help much on other than more or less local computers where you have quite open privileges. If you are on a foreign system you most likely don't have the freedom to reconfigure things like that (at least not without getting bashed by colleauges who also use the same machine :-) ). Also, every new application will need special treatment. Mar 20 '12 at 18:21
  • 6
    I've got the inverse problem, I'm used to Ctrl-w as "delete previous word" in the console, and do it by instinct even in Eclipse or Chrome where it means close tab/close current file. Quite annoying. Dec 20 '12 at 6:30
  • 1
    I have the same problem with Chrome SShInATab. How do I do ctrl-W without ctrl-W? :) Apr 18 '14 at 13:06

11 Answers 11


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...).

  • 12
    Because I used to Ctrl-Backspace in my Emacs. I knew about Ctrl-w. Alt-Backspace is new to me (+1).
    – Adobe
    Mar 17 '12 at 18:34
  • 1
    Good point, @hellork. You could intercept the control+backspace at the X server (via xmodmap) and map it to some unused character (such as alt-backspace).
    – alexis
    Mar 17 '12 at 20:56
  • 8
    The annoying thing about this is that ctrl+backspace is a really common mapping for "delete word backwards" in most GUI apps on most major operating systems. Likewise, Ctrl+W is wide-spread for "close window". Alt+w is rarely used for anything in GUIs, that I can think of. Standardisation would be great. I wonder what would be the bigger disruption, changing terminals, or changing GUIs?
    – naught101
    Feb 25 '13 at 4:29
  • 1
    @naught, Control-W is already the default word-erase key on unix terminals. Yeah it conflicts with the Windows/GUI convention, but in fact it came first--by many years. Blame Microsoft!
    – alexis
    Apr 7 '13 at 13:01

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).

  • Your first solution worked for me, actually! Second did not. May 19 '15 at 19:57
  • The second try seems to replace backspace itself rather than Ctrl-Backspace?
    – user541686
    Nov 16 '19 at 11:13
  • C-? didn't work for me, but C-H did with unix-word-rubout (see Treviño's answer). I'm on WSL with the standard windows console app. Dec 27 '20 at 17:44

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.

  • 1
    Doesn't work for me.
    – Jonathan
    Oct 12 '16 at 8:19
  • C-H worked for me with unix-word-rubout, for WSL with the standard windows console app. Dec 27 '20 at 17:44

There are some good answers here, but I solved it in Konsole with Settings->Edit Current Profile->Keyboard->Edit, then adding a mapping from Backspace+Control to \x17. (I found the ASCII code for Ctrl-w using showkey --ascii.)

  • Thanks for pointing out the thing with showkey. Thus I figured out that ALT+D for delete word in front of the cursor would correspond to \x1b\x64.
    – loki
    Aug 8 '18 at 10:02
  • Thank you, it solved my problem. In my case I need to remap the Alt+Backspace and its sequence is \x1b\x7f.
    – DDMC
    Jun 27 '19 at 12:09

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.

  • I found that my bash doesn't see backspace. But may be it's possible to make it see that.
    – Adobe
    Mar 17 '12 at 17:32
  • @adobe, what do you mean? Type 'stty' at your terminal and then read the manual about it. If ^H is set to be your erase character, you can set it to something else... if you have a good reason.
    – alexis
    Mar 17 '12 at 20:43
  • 1
    There's a good example of how to do this at github.com/calj/gtconf/blob/master/zsh/zshrc. Konsole lets you do it. Copy one of the *.keytab files from /usr/share/kde4/apps/konsole/ into ~/.kde/share/apps/konsole and modify it with the suggestions in the link above, deleting the "key Backspace" line and adding: key Backspace-Shift-Control : "\x7f" and key Backspace-Shift+Control : "\E[9;3~" Also change the title line while you're at it: keyboard "Xfree4 Modlist", for example. You can then add "\e[9;3~": backward-kill-word" to ~/.inputrc
    – Adam
    Mar 11 '13 at 1:06

In Konsole:

  • click Settings -> Edit current profile
  • click the 'Keyboard' tab -> [Edit...]
  • click the [Add] button and under the Key Combination column type Backspace+Ctrl. In the Output column type 0x08 (which is conventionally the backspace character)

Now you should be able to map that key to backward-kill-word via

# ~/.bashrc

bind '"\x08":backward-kill-word'
  • Thanks. Works for me, in xfce4-terminal at least.
    – limon
    Jun 8 '19 at 4:35
  • 1
    Try \x08 as output if 0x08 doesn't work.
    – sean
    Mar 24 '20 at 4:35

Try this:

bind '"\C-_":backward-kill-word'

Optionally add the following to ~/.inputrc to make it permanent:

"\C-_": backward-kill-word

Works on bash 4.3.11 in Kubuntu 14.04

  • 2
    Control-backspace is unlikely to be the same as Control-underscore. Dec 20 '15 at 14:48
  • 1
    Out of all the things I tried in this thread, this worked! Using "GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)" on bash on windows/WSL Aug 17 '17 at 9:31
  • This works great for me in cygwin, using GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin).
    – zagyi
    Dec 5 '18 at 9:20

To add to most of the answers here, and to explain why most answers have a comment saying "didn't work for me":

Most terminal emulaters/programs will send a different 'character' to represent ctrl+backspace. Some will not send anything different - pressing ctrl + backspace will send the same thing as backspace. That means if you have a different emulator to what the answerer is using, there's a good chance the character is different.

Some answers have mentioned modifying (via settings) what character gets sent. If you don't want to do that, the way to find out which character bash is receiving from the emulator when you press ctrl + backspace is:

  1. At the bash input, press ctrl + v (this key combination might change, but this is a very common one). This will pass through the next character without bash intepreting it.
  2. press ctrl + backspace
  3. the sequence that appears at the prompt is the character sequence sent by the emulator for ctrl + backspace.
  4. repeat the process with regular backspace to confirm it is different from ctrl + backspace.
  5. If it is the same, you will have to try the method of changing the terminal settings.

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.

  • 5
    I have Ctrl-w binded to "close tab" in Emacs, FireFox, Krusader - so I set it to be a tab-closing combination in Konsole also.
    – Adobe
    Mar 20 '12 at 17:59

This command worked for me:

stty werase ^H

You can use AutoKey with a Window Filter to remap <ctrl>+<backspace> for your favorite terminal application: https://unix.stackexchange.com/a/669238/492533

New contributor
nielsek is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.