Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List current existing or applied key bindings made via bindkey

Tags:

zsh

My ZSH has at some point been told to bind Delete to some complicated function, key sequence, or macro, and I want to remove this binding from my configuration. In order to better find where this binding is being set, I'd like to see what Zsh is actually doing when I hit Delete.

How can I see a list of all the currently existing key bindings present in my Zsh environment?

like image 618
Cory Klein Avatar asked Aug 30 '25 17:08

Cory Klein


1 Answers

Just run bindkey with no arguments:

$ bindkey
"^A"-"^C" self-insert
"^D" list-choices
"^E"-"^F" self-insert
"^G" list-expand
"^H" vi-backward-delete-char
"^I" expand-or-complete
"^J" history-substring-search-down
"^K" self-insert
"^L" clear-screen
...

However, the particular behavior you are describing with regards to Delete can be resolved by adding this to your .zshrc:

bindkey    "^[[3~"          delete-char
bindkey    "^[3;5~"         delete-char

Explanation

Depending on the terminal, Delete generates one of the following character sequences:

  • ^[[3~
  • ^[3;5~

You can see which sequence your terminal uses via sed -n l as explained here.

zsh tries to evaluate the longest match. In both cases, zsh matches ^[ first, which matches Esc. If you have vi mode enabled, this tells zsh to turn it on.

After this, vi mode reads the remaining characters, which are one of the following:

  • [3~ toggle the case of the next 3 characters
  • 3;5~ repeat the last find operation 3 times then toggle the case of the next 5 characters

So if you haven't explicitly used bindkey on this character sequence, every time you press Delete with vi mode enabled, you will enter vi mode and the last character you typed will be uppercased.

Thanks to Adaephon in the comments below for help with this explanation.

like image 76
Cory Klein Avatar answered Sep 05 '25 08:09

Cory Klein