Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zsh: stop backward-kill-word on directory delimiter

Tags:

zsh

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.

like image 940
wilhelmtell Avatar asked Jan 14 '09 22:01

wilhelmtell


2 Answers

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).

like image 66
Emil Sit Avatar answered Nov 13 '22 13:11

Emil Sit


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='*?_-.[]~=&;!#$%^(){}<>'
like image 81
poolie Avatar answered Nov 13 '22 12:11

poolie