Add the following to your .zshrc file:
WORDCHARS=''
This will make only alphanumeric characters count as words.
To make additional, non-alphanumeric characters be counted as being part of a word, simply add them to $WORDCHARS. For example, this will include - and _:
WORDCHARS='-_'
Sources:
- https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-WORDCHARS
- https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#index-forward_002dword
Alternatively, for more customizable word and subword movement, try my Zsh Edit plugin.