bindkey key mappings can be very confusing to decipher. It can use multiple different notations but it's smart to use the same key notation throughout your configuration. You can print all of your current key bindings in the current keymap with
bindkey. To print the full
bindkey command to add to your
.zshrc file use
In general, you'll bind a widget so a key sequence or a key with a modifier. This can be declared in caret notation using
^, using escape sequences using
\, in octal (
\NNN), hex (
\xNN), or Unicode (
\uNNNN). None of these are particularly great for people to read. This is also tricky because it depends on your keyboard, operating system, and shell.
Here are some basics:
\E, = Escape
^[= Alt key (on some keyboards this is the same as escape)
The keys that come after the modifier can add more confusion.
Delete key binding
To delete a key binding you can use
bindkey -d $KEYS. Make sure you don't delete the characters you need for typing.
Sometimes plugins call bindkey to assign keyboard shortcuts. This can cause problems because multiple plugins can bind the same keys.
Also, the user might want a different binding(s), which will require complicated, additional
bindkey commands in
Zi provides a solution to this problem – the ability to remap the bindkeys with a short ice-modifier
Map Ctrl-G instead of Ctrl-R for the history searcher.
zi bindmap'^R -> ^G' for z-shell/history-search-multi-word
Map Ctrl-Shift-Left and Ctrl-Shift-Right used by URxvt instead of the Xterms' ones. Load with the bindkey-tracking ↔ with light-loading for anything else.
Could also separate the bindmaps with a semicolon, i.e.:
bindmap'"\\e[1\;6D" -> \\e[1\;5D ; "\\e[1\;6C" -> ^[[1\;5C' \
zi wait light-mode trackbinds bindmap'"\\e[1\;6D" -> \\e[1\;5D"' \
bindmap'"\\e[1\;6C" -> ^[[1\;5C' pick'dircycle.zsh' for \
Map space to regular space and Ctrl-Space to the
globalias widget, which expands the alias entered on the left, provided by OMZ globalias plugin.
zi bindmap='!" " -> magic-space; !"^ " -> globalias' nocompletions \
depth=1 pick=plugins/globalias/globalias.plugin.zsh for \
bindmap'…' ice has two modes of operation: normal and exclamation-mark (
bindmap'!…'). In the first mode, the remapping is being done from-key to-key, i.e.:
bindmap'fromkey -> to-key'.
The given key is changed to the second given key in the
bindkey command while loading the plugin. In the second mode, the remapping is being done from-key to-widget, e.g:
bindmap'!from-key -> to-widget'.
In this mode, the given key is being mapped to the given widget instead of the widget specified in the
bindkey command e.g.:
bindkey "^ " magic-space
bindkey " " globalias
The actual call that'll be done will be:
bindkey "^ " globalias
bindkey " " magic-space
bindmap='!" " -> magic-space; !"^ " -> globalias' ice.
bindmap'…' in light mode
When the investigation mode is on i.e.:
- when the full loading mode is being used, default in the
forsyntax, and when
zi load …is used, then the
bindmap'…'ice works normally.
In the non-investigation:
- the light mode – activated when
zi light …or the
light-modeice is being used – the
bindmap'…'is unavailable, unless the
trackbindsice is specified:
With the use of the light-mode ice and the for-syntax:
zi light-mode for trackbinds bindmap'^R -> ^G' \
With the use of the traditional syntax:
zi ice trackbinds bindmap'^R -> ^G'
zi light z-shell/history-search-multi-word
Using the UPAR shorthands
There are four special values that can be used on the left side of the bind-map: UPAR, DOWNAR, LEFTAR, RIGHTAR. They'll match up arrow, down arrow, etc. So that it's possible to do:
zi bindmap='LEFTAR -> ^F; RIGHTAR -> ^G' …
The benefit of using the UPAR, … shorthands is that they cover multiple possible cursor-key codes for each of the cursor keys so that they'll work regardless of the terminal is used.