Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Fwd: Strange behaviour in zsh's emacs bindings



On Sat, 17 Jan 2009, Ludvig Ericson wrote:

Begin forwarded message:

From: Ludvig Ericson <ludvig@xxxxxxxxxxx>

On Jan 17, 2009, at 05:16, Benjamin R. Haskell wrote:

[... example of WORDCHARS affecting '^W' behavior ...]


Sorry for my incompetence in using my own mail client.

No worries. :-)


At risk of hijacking this thread, I'm now puzzled. The behavior above simply doesn't occur for me.

I might add that I use vi keys, does that matter? I might also add that if I do dW in normal mode, it deletes ${WORDCHAR}s as well. But not using ^W.

Yep. Vi keys'll affect it.

## emacs mode
$ bindkey -e
$ bindkey "^W"
"^W" backward-kill-word

## vi mode
$ bindkey -v
$ bindkey "^W"
"^W" vi-backward-kill-word


Looking at the source, (Src/Zle/zle_word.c), it appears emacsbackwardword uses the following algorithm:

Scan backwards until you hit something that matches: ZC_iword().
Then scan backwards until you hit something that matches: !ZC_iword().


vibackwardword, on the other hand, does:

Scan backwards until you hit something that matches: !ZC_iblank().
If that something matches Z_vialnum():
 Scan backwards until you match: !Z_vialnum()
Otherwise:
 Scan backwards until you match: Z_vialnum() or ZC_iblank().


So:

emacs-mode will kill any sequence of non-wordchars, then a (possibly-empty) sequence of wordchars.

vi-mode will kill any sequence of "blank" characters, then:
1. a sequence of alphanumerics, or 2. a sequence of non-blank, non-alphanumerics


The documentation points this out. (man zshle). The 'vi-' prefixed widgets treat words as "a series of non-blank characters".


If you want to work around it you can specifically bind "^W" to the emacs-y version:

bindkey "^W" backward-kill-word


Best,
Ben



Messages sorted by: Reverse Date, Date, Thread, Author