I thought there used to be a way with Zsh on the OSX where you could view a live print out of keys to bind event ids. Something like showkey -a where it'll print out the bind key combo you just pressed. I tried the showkey brew package but that didn't seem to work.

I'm trying to fix my alt+left&right arrow word jumping sequence when using a windows keyboard with my Mac. I can't find the correct character for alt though.

2 Answers 2


bindkey, a zle builtin, will show you the current bindings, discussed in detail in man zshzle. It allows selection between a number of builtins; emacs, numerous flavours of vi.

xev will show codes for keypresses as they happen, though it's quite basic and probably won't show combinations as you might be expecting. IIRC this may be part of the XQuartz package. https://www.xquartz.org

In addition Karabiner Elements - Event Viewer shows keypresses and their codes, but in a different format to xev. This may be more appropriate.


Function and cursor keys with modifiers generally send escape sequences that consist of the escape character followed by some printable ASCII characters.

To see what escape sequence a key or key chord sends, press Ctrl+V and then that key(chord). Ctrl+V removes the next character's special meaning, so the escape character at the beginning of the escape sequence is inserted as such. For example:

mymac% ^V^[[D

The Left key sends the three-character sequence escape, left bracket, capital D. The ^[ part is a single non-printable character which is represented visually as two characters, and which zsh shows in inverse video. All standard escape sequences start with escape then either left bracket or capital O.

Alternatively, run cat then press the key.

mymac% cat

With the Alt modifier, there's an added wrinkle that it's usually encoded as the escape character followed by whatever the unmodified key sends. For example, Alt+1 sends escape, digit 1. For keys that themselves send an escape sequence, the behavior depends on the terminal: some send a different escape sequence; some send the same escape sequence; some follow the general rule and so end up sending two escape characters followed by a printable character. In that last case, with the Ctrl+V method, only the first escape character is inserted literally, and then the key has its normal effect. With the cat method, you'll see something beginning with ^[^[.

Many terminals send the same escape sequence for a given key with a wide range of modifiers. Good terminals allow you to configure escape sequences. This is possible both with Terminal and with iTerm (in both cases, from the “Keys” or “Keyboard” tab of each profile).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .