Using ^W (unix-word-rubout) I can easily delete a single "word" from the current command in my bash shell.

However, when dealing with quoted arguments that contain spaces (or unquoted arguments containing backslash-escaped spaces) this doesn't work nicely as it only deletes one word and not the whole argument.

So I'm looking for a way to delete a whole argument.

Example (cursor is always at the end):

$ foo --bar "foo bar" meow
[black magic]
$ foo --bar "foo bar"
[black magic]
$ foo --bar
[black magic]
$ foo
  • Is switching to zsh an option? (I don't know how to do it in zsh either offhand, but it has some command line parsing code accessible to the line editor (or at least the completion system), so that should make it easier). Commented Apr 5, 2013 at 22:02

1 Answer 1


Bash has readline commands that aren't bound by default. You can find them at reference: http://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html#Bindable-Readline-Commands

The command you are looking for is called shell-backward-kill-word. You have to select a shortcut first. Let's use Ctrlp, since it's "previous command" - same as up arrow.

bind '"\C-p": shell-backward-kill-word'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .