When writing a command on the bash command line, I can use CTRL+w to delete a word backwards, or ALT+d to delete word forwards.

The problem is, that these two shortcuts are not exactly complementary: CTRL+w deletes everything up to a space, whereas ALT+d deletes only up to any non-alphabetic character (i.e. stops at /)

Is there a shortcut that acts as ALT+d, but backwards?

So that when I am at the end of /etc/hostname and press shortcut, I end up with /etc/.


bind -p gives you the current bindings. You'll find that Ctrl+W is bound to unix-word-rubout and Alt+D to kill-word:

"\C-w": unix-word-rubout
"\ed": kill-word

If you do a bind -p | grep kill-word, you'll find:

"\e\C-h": backward-kill-word
"\e\C-?": backward-kill-word

Some terminals send ^H upon Backspace and some other ^? which is why there are two bindings. That makes it that Alt+Backspace should be what kills a word backward at least on those terminals where Alt+X sends the ESC character followed by X.

There are some terminals however that send X with the 8th bit set (0xD8) upon Alt+X (though they are becoming rarer and rarer, as that doesn't make much sense this new UTF-8 world). In those, you'll have to press Esc and then Backspace, or you can set convert-meta to on in the readline configuration (for instance with bind 'set convert-meta on'), but then you won't be able to input non-ascii characters.

  • bind -p indeed prints current bindings (several hundred lines, actually). Are these the default bindings (i.e. hardcoded) or are they defined somewhere? On my Debian Wheezy, the /etc/inputrc file contains only few lines. Where do they come from, if not from /etc/inputrc ? – Martin Vegter Mar 8 '14 at 22:21
  • @MartinVegter, yes, they are the default bindings and documented. See info --index-search=backward-kill-word bashref – Stéphane Chazelas Mar 9 '14 at 8:42

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.