Zsh keybindings

From wikinotes

Documentation

man zshzle https://man.archlinux.org/man/extra/zsh/zshzle.1.en

Overview

  • keybindings are managed by ZLE (zsh's line editor)
  • keybindings can be made in various keymaps. ex: viins, vicmd, viopp, ...

Usage

zsh widgets can be bound to keybindings.

bindkey                  # list current keybings
bindkey -l               # list avail keymaps

bindkey    '^[i' run-help  # (emacs) bind esc-i to 'run-help'
bindkey -v '^[i' run-help  # (viins) bind esc-i to 'run-help'
bindkey -a '^[i' run-help  # (vicmd) bind esc-i to 'run-help'

See the full documentation under zshzle: ZLE Builtins.

bind arbitrary function to hotkey

# binds '_say_hello' function to 'alt-i'
function _say_hello() {
    echo "hello"
}

zle -N _say_hello
bindkey '^[o' _say_hello