Bash – Delete backward until met a char, like alt + bksp

bashzsh

Say my current line was:

/tmp/path/to/file:123

Now I'm at the end of this line, now I want to delete :123 by pressing some key combination, was that possible? (colon was merely mentioned as an example, it could be other chars, just wondering if I could bind keys to do that)

It's similar to what alt + Backspace does, but more specific on the word separator.

Bash or zsh are all welcomed.

Best Answer

Search backward for :, then delete to the end of the line: Ctrl+R : Alt+D. Ctrl+R is the history search command, and the line you're editing is part of the history. Most commands, including Alt+D, terminate the incremental history search and have their usual effect.

In vi mode: F:C

This applies in both bash and zsh (in the default configuration, I don't guarantee that there aren't exotic combinations of options in zsh that will make it react differently, and of course this assumes the default keybindings).

Related Question