Bash readline deleting till the previous slash
In bash emacs mode, is there anyway to delete till the previous slash character?
For example if i entered the command cp /usr/local/bin/reallylongincorrectfolder /home/myname/reallylong_and_correct_path
and want to just delete the reallylongincorrectfolder
.Is there any shortcut? This is a very comman scenario for me in bash.
Something like dF<char>
in vi?
Solution 1:
bind -P |grep unix-filename-rubout
To test out the keybinding with eg. Ctrl-b:
bind \\C-b:unix-filename-rubout
For permanent usage, add it to ~/.inputrc
Solution 2:
Alt-Backspace and Ctrl-w are commonly mapped to backward-kill-word
, which does that. If you want to find out what it's mapped to on your system (if anything), run bind -P | grep '^backward-kill-word'
.
As explained by @Barmar, this is different from unix-word-rubout
, which removes to the previous space boundary.
Solution 3:
Put this in your .inputrc
and start a new shell:
C-b:unix-filename-rubout
Ctrl-b now erases backwards to the next slash.
Nirvana!
Don't forget Ctrl-XCtrl-E will launch your editor so you can edit a complicated command line comfortably.