Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
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). –  Gilles Apr 5 '13 at 22:02

1 Answer 1

up vote 7 down vote accepted

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

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

bind '"\C-p": shell-backward-kill-word'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.