Skip to main content

โŒจ๏ธ Key Bindings

Inspect key bindingsโ€‹

The Zsh Line Editor (ZLE) stores bindings in keymaps. Run bindkey to list the selected keymap, or bindkey -L to print bindings as commands that can be reused in .zshrc.

Key sequences can use caret notation, escape sequences, octal, hexadecimal, or Unicode forms. Common examples include:

  • \e or \E: Escape
  • ^[: Escape, often produced by an Alt-key sequence
  • ^?: Delete
  • ^X: Control-X

Terminal emulators can encode modified keys differently. Use cat -v or a ZLE diagnostic widget to inspect the sequence generated by your terminal before adding a binding.

Add a key bindingโ€‹

Pass a key sequence and widget name to bindkey:

~/.zshrc
bindkey '^R' history-incremental-search-backward

Use bindkey -M keymap when the binding should target a keymap other than the selected one.

Remove a key bindingโ€‹

Use bindkey -r to unbind a specified string in the selected keymap:

~/.zshrc
bindkey -r '^R'

Add -R if the argument should be interpreted as a range. The -d flag does not delete an individual binding. It deletes all existing keymaps and restores the default keymap state, so it should not be used as an individual-key removal command.

See the Zsh Line Editor manual for keymap selection, binding forms, and range behavior.