Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZSH Bindkey Reverse Lookup

Tags:

linux

unix

key

zsh

Can anyone tell me what the key sequence is for these? I know if I do cat and type key presses I can get the code for it but how do I reverse that process to figure out what to press for beginning-of-line, for example?

bindkey '^[^[[D' backward-word
bindkey '^[^[[C' forward-word

bindkey '^[[5~' up-line-or-history
bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search
bindkey '^[[6~' down-line-or-history

bindkey '^[[5D' beginning-of-line
bindkey '^[[5C' end-of-line

bindkey '^[[3~' delete-char
bindkey '^?' backward-delete-char 

bindkey '^[^N' newtab
bindkey '^[[Z' reverse-menu-complete
like image 521
maletor Avatar asked Jul 29 '11 20:07

maletor


1 Answers

Tip: I've now published a more sophisticated version of the code below as part of the zsh-edit plugin.


You can use this function to do a reverse bindkey lookup:

reverse-bindkey-lookup() {
  print ${(k)terminfo[(Re)$(print -b - $1)]}
}

For example, when I run:

% reverse-bindkey-lookup '^[[Z'

I get as output:

cbt kcbt

These values you can then look up by doing

% man terminfo

and pressing / to search.


For the example above, I find:

back_tab                    cbt      bt     back tab (P)

and

key_btab                    kcbt     kB     back-tab key

Another example: If I run

% reverse-bindkey-lookup '^[[3~'

I get

kdch1

which man terminfo says is

key_dc                      kdch1    kD     delete-character key

Hopefully, you can then figure out from there what the actual key on your keyboard would be. 🙂


like image 165
Marlon Richert Avatar answered Oct 17 '22 15:10

Marlon Richert