Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
1  
Atl-Backspace –  Stéphane Chazelas Mar 8 at 20:36

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
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 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 at 8:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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