tags:

views:

425

answers:

3

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.

+4  A: 

ctrl-w does exactly what you want.

William Pursell
I read that part of the manual a zillion times, I can't believe I missed it. Thanks :)
spatz
I'll just note that after experimenting with it a little it's still not optimal since slashes are ignored as separators, which is annoying when working with paths.I added the line `"\ew": unix-filename-rubout` to `/etc/inputrc` and now M-e deletes a word while ignoring hyphens but does treat slashes as separators.
spatz
A: 

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'

Eric
A: 

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.

webXL