ZLE: Key bindings codes list

zlezsh

I know that in

bindkey '\ep' autosuggest-accept-suggested-small-word

the \e refers to the ⎇ Alt key. I also know that C- refers to the ⎈ Ctrl key.

Is there a list referencing all the keys because I have the hardest time to understand how ZLE works and which key combination I should use to bind autosuggest-accept-suggested-small-word to a keyboard shortcut starting with the ⌘ Cmd key.

For example: To which keys are these keybindings referring: ^~u, ~w, ^@j (these are keybindings that I found in the ttscoff keybindings settings file)?

Best Answer

^ in ZSH (and many other softwares; see for example stty -a) refers to control key e.g. for control-L to clear the screen one might find in the ZSH keybindings list

% bindkey | grep clear
"^L" clear-screen
% 

I cannot comment on how ^~u ~w ^@j in the ttscoff keybindings relate to ZSH. That software appears unrelated to ZSH; the full list of what ZSH recognizes can be found in the zshzle(1) manual, which for some version of ZSH (do instead check the manual for the version you have and do not blindly assume that this list is correct for that version of ZSH) includes

          \a     bell character
          \b     backspace
          \e, \E escape
          \f     form feed
          \n     linefeed (newline)
          \r     carriage return
          \t     horizontal tab
          \v     vertical tab
          \NNN   character code in octal
          \xNN   character code in hexadecimal
          \uNNNN unicode character code in hexadecimal
          \UNNNNNNNN
                 unicode character code in hexadecimal
          \M[-]X character with meta bit set
          \C[-]X control character
          ^X     control character

To make the Apple command key generate codes in the terminal requires that the terminal program be configured to do so; the instructions for this will vary depending on whether you are using Terminal.app or iTerm.app or something else (dig around in the preferences or check the manual).

With iTerm.app (this may change; GUI apps tend to move things around over time) try the iTerm2 menu, Preferences, Keys, find the widget to add something, and then "send hex code" 0x02

send hex code 0x02

Then in ZSH bindkey this sequence

% xxd
^B
00000000: 020a                                     ..
% screencapture -s hexcode.png
% bindkey '^B' clear-screen
% 

and now splat-shift-option-O should cause ZSH to clear the screen; instead bindkey your desired widget and set that in your configuration:

bindkey '^B' autosuggest-accept-suggested-small-word

or whatever other binding that works for you. Be sure to run bindkey and inspect that no other existing widget that you want to use uses the key code...

Related Question