In readline(3) I should be able to map Control-Backspace to the same function as Control-W (unix-kill-rubout). Regardless of what I put in ~/.inputrc I'm unable to get this to be recognized.

\C-\b: unix-kill-rubout

...for instance does not work. Can I map Control-Backspace to the unix-kill-rubout in readline?

7 Answers 7



"\C-_": unix-word-rubout

to .inputrc seems to work for me.

The C-_ represents control underscore. This is what my terminal sends when pressing Ctrl+Backspace.

Pressing Ctrl+V then a key combination will echo its code to the console. For me, pressing Ctrl+V then Ctrl+Backspace echoes ^_ with ^ meaning Ctrl. In .inputrc \C- is the Ctrl modifier so \C-_ is what's needed here. You can use this technique to determine other key combinations you may want to use.

  • How do you check what the terminal sends/receives when you press some keys? (in putty for example)
    – N M
    Feb 12, 2019 at 5:47
  • Rather, how do you translate this to emacs keybindings?
    – N M
    Feb 12, 2019 at 7:27

As graywh points out backspace is often represented by ^?. In order to bind to ctrl+bksp in your .inputrc file you may need modify your readline library. This ubuntu tutorial includes a new .keytab file which can override the default output.

On my system this let me add "\e[9;3~": backward-kill-word to my .inputrc.

As readline behavior seems to vary somewhat based on your system, it's worth noting I'm using Konsole on Kubuntu.


I doubt your terminal will send a special code for ctrl-backspace. Backspace is normally ctrl-?, and you can't add another ctrl modifier to a ctrl character.

One alternative might be to have your terminal send a special escape sequence for Ctrl-Backspace, then map that in your readline config.

  • Backspace is ^H officially. Delete is ^?, but my terminal sends the delete version when backspace is pressed. This is why binding \C-\b didn't work.
    – jiggunjer
    Feb 25, 2017 at 17:29
  • @jiggunjer In ASCII, yes, but I'm talking about what the Backspace key does.
    – graywh
    Mar 1, 2017 at 19:05

This works for me (in urxvt, bash):


For the linux terminal, you can do it by modifying the keymap you load on startup. In ubuntu my default it loads /etc/console-setup/cached.kmap.gz. If you find the entry corresponding to Ctrl-Backspace (probably Control-Delete is listed as Backspace already) then you could change that to Control_w. Not sure about terminal emulators, but konsole (the default KDE terminal emulator) has quite nice settings for keybinds. Hope that helps :)



For Mac users logging into a multiple Linux systems:

If you don't have access to the .inputrc or any other configuration files on the system you are accessing and want things to work universally no matter which system you are logging into, here is a GUI solution using Iterm2.

I installed Iterm2 on my mac from the command line on my mac by using brew (https://brew.sh)

brew cask install iterm2

How to bind a key sequence to the control key in Iterm2

  1. Download the free application “Key Codes" from the app store. Install it from the link below and then open it.

  2. Hit the Ctrl+some key in this case I’ll use Ctrl+w.

    How to get the hex code

  3. The hex code in the red square is the code we want to send to the terminal

  4. Now map your key sequence in Iterm2 by opening it from the Applications folder->Preferences->Keys->+.

How to map the command to the hex code

  1. This will now map opt+←delete to Ctrl+w in the terminal, but you can use it to map any key to another one. I know Ctrl+w is a bad example for Emacs since it doesn't support Ctrl+w but you can use this methodology for Emacs compatible shortcuts.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .