Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing word delimiters in bash

Tags:

bash

readline

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.

like image 735
drrlvn Avatar asked Aug 31 '09 12:08

drrlvn


2 Answers

ctrl-w does exactly what you want.

like image 112
William Pursell Avatar answered Sep 29 '22 22:09

William Pursell


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'

like image 28
Eric Avatar answered Sep 30 '22 00:09

Eric