How to delete one directory level in a command argument (up to a slash) on ZSH command line

command linetext editingzsh

I just switched from bash to zsh. One thing that is different and a bit annoying from me that Alt-Backspace removes the whole argument instead of just one word. I'm used to using it to remove one level of directory in a file path on the command line. Is there a keystroke for zsh that I could use instead?

Best Answer

This is a frequently asked question, see e.g.

However, some answers seem to be outdated (contribution to the mailing list dating back to 2001) or rather complicated.

In the easiest case (and answering your specific question to delete back to a slash) I'd boil it down to

autoload -Uz select-word-style
select-word-style bash

As always with zsh you can, but sometimes also have to do much more customization if it does not suit your needs out of the box. Because I'm no expert for select-word-style (I've written my own widgets for that purpose), please refer to man zshcontrib for a detailed explanation of the options.

Related Question