2

I've recently started using ZHS with oh-my-zsh script pack. It does excellent job except of weird ^W shortcut behavior.

For example if I have following command line and symbol ▮ denotes cursor position.

$ ./command_name --option1 value --option2=value ▮

Sequentially pressing ^W for several times I'd get following content in command prompts:

$ ./command_name --option1 value --option2=▮
$ ./command_name --option1 value --▮
$ ./command_name --option1 ▮
$ ./command_name --▮
$ ./command_▮
$ ./▮

What bugs me is that after third press cursor stops not after deleting --, but also eats value. I suspect that all symbols such as "_-" are considered as separators as spaces and zsh continues eating symbols until it deletes some non-separator chars, but I have no idea how to change this behavior.

2

2 Answers 2

3

In order to fix this (default) behavior you want to have Zsh use vi-style backward-kill-word.

Put this in your ~/.zshrc:

bindkey '^W' vi-backward-kill-word

Now, it will kill to the following positions:

$ ./command_name --option1 value --option2=▮
$ ./command_name --option1 value --option2▮
$ ./command_name --option1 value --▮
$ ./command_name --option1 value ▮
$ ./command_name --option1 ▮
$ ./command_name --▮
$ ./command_name ▮
$ ./▮
$ ▮
0
1

Because in your case WORDCHARS doesn't contain -, _, ., /, or =, from the line editor's perspective it looks like:

$   command name   option1 value   option2 ▮
$   command name   option1 value   ▮
$   command name   option1 ▮
$   command name   ▮
$   command ▮
$   ▮

In other words, =, --, _, and ./ are treated as white spaces.

Adding more word characters will not only fix backward-kill-word but all word-wise widgets, among which copy-prev-word, transpose-words, up-case-word, and many others.

It will also affect glob pattern expansion. For example, adding + makes !" /bin/?[![:WORD:]]## match /bin/c++, /bin/g++.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .