How to remove a zsh keybinding if I don’t know what it does

keyboard shortcutszsh

How do I disable a keybinding if I don't know what it is or what it's triggering?

I have my zsh key mode set to vi-mode, through bindkey -v.

To do a history search, I press Esc to get to "command mode", and then / to start the search. However, if I press them too fast, it does something else, but I don't know what! I assume Esc-/ is some keybinding, but I don't know what it is. How do I find this and turn it off?

Best Answer

After some searching, I've found the answer:

To discover what escape sequence the key combination is triggering, follow this excellent answer:

echo "CtrlVEsc/"

Which displays, for me, as: echo "^[/". CtrlV forces the following key to display as an escape sequence instead of being interpreted. So now we know we're trying to find what is bound to "^[/".


To list all zsh key bindings, simply execute bindkey with no args:

$ bindkey
"^A"-"^C" self-insert
"^D" list-choices
"^E"-"^F" self-insert
"^G" list-expand
"^H" backward-delete-char
...
"^Y"-"^Z" self-insert
"^[" vi-cmd-mode
"^[," _history-complete-newer
"^[/" _history-complete-older   ### <--- Here it is.
"^[M" vi-up-line-or-history
"^[OA" vi-up-line-or-history
...
"^\\\\"-"~" self-insert
"^?" backward-delete-char
"\M-^@"-"\M-^?" self-insert

So, having decided that I don't care about _history-complete-older, I'm just going to remove it. I added this to my .zshrc:

# Unbind the escape-/ binding because it gets triggered when I try to do a history search with "/".
bindkey -r "^[/"

If, instead, you just want to rebind it to some other key, you might use:

bindkey -r "^[/"
bindkey "<some-other-key-combo>" _history-complete-older