Partially delete path in zsh (Option + Backspace)

Solution 1:

An arbitrary number of alphabetic characters and digits as well as chars defined by WORDCHARS are considered all one word in zsh.

The default value of WORDCHARS is:

% echo $WORDCHARS
*?_-.[]~=/&;!#$%^(){}<>

By defining another/a new WORDCHARS in .zprofile (and/or .zshrc|... - depends on how you configured your zsh environment), you can modify the behaviour of werase (word erase - usually ctrl/^w).

Simply add the line export WORDCHARS='*?_-.[]~=&;!#$%^(){}<>' in .zprofile|..., close the Terminal window or source .zprofile|... and werase works as you want afterwards.

Keep in mind that other shortcuts (like alt/⌥) will also be affected then.


If you want a different behaviour, check this question & answer: zsh: using different WORDCHARS for kill-word and forward-word / backward-word