Zsh backward-delete-word does not recognize "/" character
I want ctrl-W on Zsh to stop when it encounters the "/" character. I have the following in my .zshrc file, but it doesn't stop on "/". What is going on?
default-backward-delete-word () {
local WORDCHARS="*?_[]~=/&;!#$%^(){}<>"
zle backward-delete-word
}
zle -N default-backward-delete-word
bindkey '^W' default-backward-delete-word
Solution 1:
The problem is, that /
is part of your WORDCHARS
.
According to zshparam(1)
:
WORDCHARS
<S>
A list of non-alphanumeric characters considered part of a word by the line editor.
So if you want zsh to consider /
as a word separator, it should not be in WORDCHARS
. I would also suggest using single quotes instead of double quotes when defining it - especially as there is a $
in there, which may lead to unwanted expansions.
local WORDCHARS='*?_[]~=&;!#$%^(){}<>'