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?
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
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 characters3;5~ repeat the last find operation 3 times then toggle the case of the next 5 charactersSo 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With