I want to change the delimiters bash (or readline) uses to separate words. Specifically I want to make '-'
not delimit words, so that if I have the text
ls some-file
and I press Alt-Backspace
it deletes the entire some-file
text and not just up to the '-'
char. This will also cause deletions of long flags like --group-directories-first
faster and easier, needing only one key-press.
I believe that this is how zsh behaves and I'd like to make bash behave in the same way.
ctrl-w does exactly what you want.
One thing to keep in mind is that the bash key mapping for ctrl-W will not work if you have the stty werase setting assigned to ctrl-W. If you run "stty -a" and you see "werase = ^W" that will take precedence and use the tty idea of what a word boundary is. The tty's idea of a word boundary is usually whitespace, whereas bash's backward-kill-word function also includes - and /.
If you want to make Alt-Backspace do the same thing as the werase setting, you can do this: bind '"\M-\C-h": unix-word-rubout' bind '"\M-\C-?": unix-word-rubout'
Also, if you actually wanted to make ctrl-W do what Alt-Backspace does, you would do: stty werase undef # unless you do this, bash ignores the follow bind command bind '"\C-w": backwards-kill-word'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With