[Howto] key bindings in shells

This short howto explains how to figure out which key binding is connected with which key.

I just read a post about zsh and once again was curious about the possibilities and the advantages of that shell. The author provided a customized .zshrc which I used for tests. And despite the good intentions of the author it was almost unusable.

One reason for that was that the key bindings weren’t right: when I pressed the DEL key a new char “~” appeared instead of another one deleted. POS1 and END keys also just produces more “~” chars. This was due to the fact that the key bindings for the keys were set to the wrong keys: bindkey '^[OF' end-of-line simply didn’t work for me.

So I had to figure out the right key binding – this is easily done by calling cat and afterwards press the key which key binding you’d like to have. For me it was ^[[4~, and I used it to replace the ^[OF from above. It worked, and now the appropriate keys work on my system as well with:

# the "del" key
bindkey '\e[3~' delete-char
# home
bindkey '^[[1~' beginning-of-line
# end
bindkey '^[[4~' end-of-line
# insert
bindkey '\e[2~' overwrite-mode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.