You are not logged in.
Pages: 1
Hello,
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:
optipng images/1.png
Then pressing ctrl+w gives this:
optipng
While I'd like to have a shortcut that gives this:
optipng images/
Does that exist? I couldn't find any.
Thanks!
Offline
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:
"\C-e\C-w": unix-filename-rubout^e^w will then delete backwards, respecting slashes as word boundaries.
Last edited by falconindy (2012-05-06 18:28:28)
Offline
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.
Offline
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 ![]()
Strange...
Last edited by aardwolf (2012-05-06 19:50:16)
Offline
OP may be interested in putting
set -o viin their .bashrc.
Pressing v will then let you edit the current command in $EDITOR.
Offline
Pages: 1