List of zsh bindkey commands - zsh

Where can I find a list of zsh commands that I can use with bindkey, with descriptions?
Each time that I look for name of some standard action (e.g., end-of-line), I need to google and guess that the command found is what I look for.
Related:
Interpret zsh bindkey escaped sequences (SO)
The Z-Shell Line Editor (doc)

bindkey -l will give you a list of existing keymap names.
bindkey -M <keymap> will list all the bindings in a given keymap.
If you use the zsh command line in emacs mode, then the emacs keymap is likely to be most important for you.
If you use it in vi mode, then you’d be interested in viins and vicmd.
(See the zshzle(1) man page for more details.)
Once you have a list of keybindings, you can search the official ZLE documentation for the name of the action (or “widget” in zsh parlance).

zle -al
lists all registered zle commands

Commands available for use in the line editor are referred to as widgets. The standard widgets are listed in the zshzle manpage in the STANDARD WIDGETS section. That manpage is also available from the zsh website

Zsh Line Editor Doc: https://web.cs.elte.hu/local/texinfo/zsh/zsh_10.html
Look up system current bindkey setting: $ bindkey, eg($ bindkey|grep case, looking for down-case);
$ zle -al used for list all registered zle commands;
Bind your personal key for zsh command , $ vim ~/.zshrc, add
# bindkey
bindkey "^U" backward-kill-line
bindkey "^u" backward-kill-line
bindkey "^[l" down-case-word
bindkey "^[L" down-case-word
# alt+<- | alt+->
bindkey "^[f" forward-word
bindkey "^[b" backward-word
# ctrl+<- | ctrl+->
bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
See other things: oh-my-zsh down-case-word bug: https://github.com/robbyrussell/oh-my-zsh/commit/55a9d685fd960390a4f400ac461d901049a78beb

I'm on zsh via putty. For me the bindings were different. You can find this out with CTRL+V followed by for example the left arrow. It will display the used character sequence. So for me it was:
bindkey "^[[D" backward-word
bindkey "^[[C" forward-word
bindkey "^H" backward-kill-word

After installing oh-my-zsh, I typed bindkey 'anything' then press tab, then say yes. The list of available bindkeys will be flushed out

Related

How to make zsh keybind between emacs mode and vi mode?

I want to bind a key to toggle emacs mode and vi mode,which I use oh-my-zsh plugins(vi-mode).
I tried Is there a way to switch Bash or zsh from Emacs mode to vi mode with a keystroke?
I also try to bindkey like
bindkey '^[e' 'set -o emacs'
bindkey '^[v' 'set -o vi'
But it's not work for me.
Does any way to toggle vi/emacs or keybind to set keymap?
Thanks a lot !
bindkey is used for binding keys to ZLE widgets not any random command. So what you have guessed at is not going to work. You could write a custom ZLE widget to switch keymaps:
select-emacs() { set -o emacs }
zle -N select-emacs
bindkey '^[e' select-emacs
In practical terms, I wouldn't recommend this. If you want a hybrid approach, it is better to select emacs mode but bind a key to vi-cmd-mode. In fact Ctrl-X,Ctrl-V is bound to this by default. You might even bind the escape key to vi-cmd-mode - where emacs key sequences involve an initial escape press, that can mostly be replaced by Alt. If you're used to typing it with the actual escape key, you may be able to replace it by a custom widget in vi command mode.
I finally "found out" how to toggle vi and emacs mode with a singel key, e.g. [alt]+[i] in zsh
# in the .zshrc
# toggle vi and emacs mode
vi-mode() { set -o vi; }
emacs-mode() { set -o emacs; }
zle -N vi-mode
zle -N emacs-mode
bindkey '\ei' vi-mode # switch to vi "insert" mode
bindkey -M viins 'jk' vi-cmd-mode # (optionally) switch to vi "cmd" mode
bindkey -M viins '\ei' emacs-mode # switch to emacs mode
now you can toggle from emacs-mode to vi-mode and from vi-mode (both insert or normal mode) to emacs-mode

What is the bindkey equivalent to bind -x?

In this question, the inimitable Dennis Williamson mentions how to bind a keystroke to a command that will run in the background of the Bash shell, with bind -x. How can the same thing be done in Zsh?
(I couldn't find this in the zshzle man page, but it's possible that I overlooked it.)
You can use zle -M to display info underneath your command line. For example:
.who() {
zle -M "$(who)"
}
# Create a new widget `who` that calls our function `.who`.
zle -N who .who
# Bind said widget to alt-shift-W.
bindkey '^[W' who

How to remove a keybinding

So I have zsh installed and when i run the command:
bindkey | grep kill-word
I see the following results:
"^W" backward-kill-word
"^[^H" backward-kill-word
"^[D" kill-word
"^[d" kill-word
"^[^?" backward-kill-word
I want to remove some of these key bindings, how do I go about doing that?
Say you wanted to remove the lower case version of kill-word. bindkey -r will remove the given binding.
bindkey -r '\ed'

Deleting word like bash in zsh (autoload is not working)

I have the following code in my .zshrc and I have .oh-my-zshell installed.
The following line, however, does not work as it is described in other posts:
autoload -U select-word-style
select-word-style bash
Is there other options I need to add in order to make it work?
if you want '^W' bash behavior you may need to unset WORDCHARS or place them in seperate functions and bind you newly created functions.
As i am not using you example, here is my way to accomplish this, second example is also for bash compatibility using <A-Backspace> which respect WORDCHAR defined as follow
x-bash-backward-kill-word(){
WORDCHARS='' zle backward-kill-word
}
zle -N x-bash-backward-kill-word
bindkey '^W' x-bash-backward-kill-word
x-backward-kill-word(){
WORDCHARS='*?_-[]~\!#$%^(){}<>|`##$%^*()+:?' zle backward-kill-word
}
zle -N x-backward-kill-word
bindkey '\e^?' x-backward-kill-word

Fish-style Autosuggestion in Zsh?

Is there a way to do the type of auto-suggestion Fish does in Zsh?
https://github.com/tarruda/zsh-autosuggestions does exactly what I wanted. If you want fish-style autopredictions in zsh, use that.
Zsh has predict, run the commands below this and then hit Ctrl-X 1 or just type predict-on to give it a try
#-*-shell-script-*-
autoload predict-on
autoload predict-off
# you may also wish to bind it to some keys...
zle -N predict-on
zle -N predict-off
bindkey '^X1' predict-on
bindkey '^X2' predict-off

Resources