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.
dF<char> in vi?
bind -P |grep unix-filename-rubout
To test out the keybinding with eg. Ctrl–b:
For permanent usage, add it to
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.
Put this in your
.inputrc and start a new shell:
Ctrl–b now erases backwards to the next slash.
Don’t forget Ctrl–XCtrl–E will launch your editor so you can edit a complicated command line comfortably.