2

In zsh Option + Backspace deletes the whole path on a prompt. For example:

ls /usr/local/bin

Option + Backspace returns:

ls

How can I set the same behavior so that the shortcut deletes just one word, till the next delimiter, like:

ls /usr/local/bin

Option + Backspace should return:

ls /usr/local/
  • This seems to be related how zsh treats a word. Not sure how to change the behavior yet. If anyone knows please let me know. Thank you. – Emil Feb 14 at 21:22
2

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

|improve this answer|||||
  • That's exactly what I end up doing but forgot to answer my question. Thank you. – Emil Feb 16 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .