The shortcut ctrl+w in bash deletes the word at the cursor until it reaches whitespace. This is often very handy. But sometimes I'd like to have a shortcut that deletes up to the last non-letter (or non-identifier) character, instead of up to whitespace.
E.g. if I have this in my terminal:
Then pressing ctrl+w gives this:
While I'd like to have a shortcut that gives this:
Does that exist? I couldn't find any.
This sort of behavior is documented in readline(3), not by directly by bash. You can get this behavior by binding the 'unix-filename-rubout' action, e.g. by adding the below to your .inputrc:
^e^w will then delete backwards, respecting slashes as word boundaries.
Last edited by falconindy (2012-05-06 18:28:28)
With the cursor at the end of the line, I would have used Alt+b to move backwards by punctuation-separated word, then used Ctrl+k to delete from the cursor to the end of the line.
Alt+b recognizes hyphens,underscores and slashes, as well as whitespace, as word boundaries. Alt+f works similarly but forwards. Ctrl+b and Ctrl+f are backwards and forwards by character – those arrow keys sometimes seem such a long distance away for my fingers that I use these shortcuts frequently.
Some other keyboard navigation and editing that I use:
Ctrl+a and Ctrl+e are shortcuts to the beginning and end of a line.
Ctrl+d deletes a single character; Alt+d deletes forward by punctuation-separated word.
Ctrl+Underscore undoes line edits one-by-one, you can repeat till you've finally restored to the bare prompt.
Hmm, whoever designed those bash shortcuts did it really weird, they're so inconsistent...
Deleting a word backwards does not respect punctuation, and uses CTRL in the shortcut.
Deleting a word forwards does respect punctuation, and uses ALT in the shortcut.
Not to mention that there's no connection at all between the letters and the action for those
Last edited by aardwolf (2012-05-06 19:50:16)