3

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

1

1 Answer 1

6

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.

2
  • 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 ? Commented Mar 8, 2014 at 22:21
  • @MartinVegter, yes, they are the default bindings and documented. See info --index-search=backward-kill-word bashref Commented Mar 9, 2014 at 8:42

You must log in to answer this question.

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