You can set the special characters that are considered part of a word with the
WORDCHARS variable. This has influence on how words are deleted by
Ctrl + W:
However it also has influence on
Ctrl + Alt + H. We want this behavior to only apply to
Ctrl + W. But there's a trick that we can do. Let me explain:
You can rebind the key combinations to different functions (see
man zshzle). And there are 2 functions that actually have the same behavior:
You can also redefine these functions with
zle -N <func>. I'm not completely sure how it works but you get an idea if you read the code, anyway, it does the trick.
By default both
Ctrl + W and
Ctrl + Alt + H are mapped to
backward-kill-word. So we can redefine
backward-delete-word and then bind that to
Ctrl + W:
# Make `Ctrl + W` behave like it does in Bash, deleting words separated by
# spaces. We do this by redefining the `backward-delete-word` function and bind
# that to `Ctrl + W`.
backward-delete-word() WORDCHARS=$SPACE_WORDCHARS zle .$WIDGET
zle -N backward-delete-word
bindkey "^W" backward-delete-word
Ctrl + W deletes bigger words than
Ctrl + Alt + H!
Very sadly I'm now discovering that this approach lacks some functionality, when you delete a word, it doesn't get yanked to the paste buffer (Ctrl + Y). Haven't found a solution for that yet..