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

Re: emulate bash key bindings



On 08.01.2020 13:00, Peter Stephenson wrote:
On Tue, 2020-01-07 at 21:38 +0300, Andrey Butirsky wrote:
Hello,
after 25 years of bash, I'm doing my first steps with Zsh. I'm trying to reproduce main bash key bindings in Zsh, so I started with: autoload -U select-word-style
select-word-style bash
But sill, I need to have different word boundaries for some bindings,
e.g Ctrl+W should kill space-delimeted word.
What is the best way to achieve that? Can I avoid creating custom widgets?
The most configurable way is to use the special widget, the same one
that you've now got bind to the usual backward-kill-word functions, but
under a different name.  Then you can set a special style for the
behaviour.  Then you have all the same possibilities as the widget
functions at your fingertips, without having to redefine any functions.


# Create widget backward-kill-space-word, using the generic
# backward-kill-word widget function.
zle -N backward-kill-space-word backward-kill-word-match
# Tell it to use "space" style for words.
zstyle ':zle:backward-kill-space-word:*' word-style space
# Bind it.
bindkey '^W' backward-kill-space-word


The zshcontrib manual lists the various styles.

pws

Thanks to all for answering!

Actually, the solution with styles is what I came to myself, just used aliases instead of creating new widgets (zle -A forward-word space-forward-word). But binding with dot-prefixed widget names seem the most compact solution for me: "bindkey '^w' .backward-kill-word", thanks!

Still, both solutions do not seem very obvious, at least for new user.
So maybe we should emphasize it in the documentation?
I think a few extra examples in section introducing 'select-word-style' command would be enough.



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