Reputation: 8437
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.
Upvotes: 11
Views: 4616
Reputation: 1630
This might be useful: Ctrl-r will initiate a reverse-i-search (for history AND the current line), so you can just hit space and escape and it's back where you want it, or ctrl-r again (after hitting the first space) if you want to go back one more arg. Then you can optionally kill the rest of the line.
Especially useful if you're dealing with long path arguments (e.g. in cp or diff), and need to modify the end of the first arg.
Tried to get \M-b to do this, but it stops at slashes.
Upvotes: 1
Reputation: 5365
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'
Upvotes: 5