zsh: stop backward-kill-word on directory delimiter

Zsh

Zsh Problem Overview


In zsh, how can I set up the line editor such that backward-kill-word stops on a directory separator? Currently in my bash setup, if I type

cd ~/devel/sandbox

and then hit C-w point will be right after devel/. In my zsh setup, point would be after cd . I'd like to set up zsh so it behaves similarly to bash.

Zsh Solutions


Solution 1 - Zsh

For recent versions of zsh, you can simply add:

autoload -U select-word-style
select-word-style bash

to your zshrc as described in the zsh manual (also man zshcontrib).

Solution 2 - Zsh

Another option is to set WORDCHARS (non-alphanumeric chars treated as part of a word) to something that doesn't include /.

You can also tweak this if you'd prefer ^w to break on dot, underscore, etc. In ~/.zshrc I have:

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

Solution 3 - Zsh

A quick google reveals:

Backward Kill

Or, perhaps a better fix:

Bash Style Backward Kill

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwilhelmtellView Question on Stackoverflow
Solution 1 - ZshEmil SitView Answer on Stackoverflow
Solution 2 - ZshpoolieView Answer on Stackoverflow
Solution 3 - ZshJames Van HuisView Answer on Stackoverflow