In zsh
by default, CTRL+w and ALT+Backspace seem to have exactly same effect.
How can I keep CTRL+w as it is, and change ALT+Backspace so that it stops at non-alphanumeric characters.
ie, when the cursor is at the end of following command: echo /aaa/bbb/ccc
, pressing CTRL+w should leave echo
, while pressing ALT+Backspace should leave echo /aaa/bbb/
.
UPDATE
based on answer from @Thomas Dickey
, I have added the following to my .zshrc
:
my-backward-delete-word () {
local WORDCHARS='~!#$%^&*(){}[]<>?+;'
zle backward-delete-word
}
zle -N my-backward-delete-word
bindkey '\e^?' my-backward-delete-word
Now the command line editor behaves differently than I expected.
For example, the single quote character '
is not enumerated in my WORDCHARS
, so when I press Alt+BackSpace, the backward-delete-word
should stop at '
.
This works in in first example, but not in the second:
$ echo 'asdf'
$ echo '
$ echo '=asdf'
$ echo '=
$
in the second example, I had echo '=
left on the commandline. After I have pressed Alt+BackSpace second time, everything was eaten, including echo
. I would have expected only =
should have been eaten, because it should have stopped at '
.
Why is this not working as expected?
alt+backspace
? When I tried your example, I get:No such widget tcsh-backward-delete-word
. – Martin Vegter Oct 05 '16 at 06:06tcsh-backward-delete-word
(with$WORDCHARS
set to the characters you want for "works"). – Thomas Dickey Oct 05 '16 at 07:50no such widget ...
.