When I hold the Shift- and the Ctrl-Key on the keyboard and press the arrow-keys, then character-combinations are shown on the screen: ;6D;6A;6C;6B

What's the meaning of these characters ;NumberLetter?

1 Answer 1


The input on a terminal is a sequence of characters (or more precisely a sequence of bytes). Non-printable input, such as function and arrow keys, has to be encoded as one or more characters. A few keys are encoded as control characters, for example ^I (HT, Ctrl+I) for the Tab key. But there aren't nearly enough control characters to encode all key combinations. So function keys and cursor keys are encoded as sequences of multiple characters. In practice, all terminals use escape sequences that start with the character ESC (Escape, ^[) followed by some printable characters. The details of the encoding can vary between terminals and can depend on the terminal configuration.

Escape sequences have a variable length, so the only way to know when one ends is to know how it's constructed. If the application running in the terminal (for example the shell) recognizes the escape sequence as a key chord, it invokes whatever functionality is bound to that key chord. If the application doesn't recognize the escape sequence, there's a point where it gives up and treats subsequent characters as ordinary characters.

The de facto standard encoding for cursor keys is that Up sends ^[[A (where ^[ means an escape character, not the two-character sequence circumflex-bracket), Down sends ^[[B, Right sends ^[[C and Left sends ^[[D. Modifiers are indicated with a semicolon and a number, and for cursor keys an extra 1 before the semicolon. The number 6 indicates the modifiers Ctrl+Shift. See this answer for more details.

When you press Ctrl+Shift+Left, the terminal sends ^[[1;6D (recall that ^[ is an escape character here). The shell reads ^[[1 and, at that point, notices that none of its key bindings start with these three characters. So it gives up (and it might beep if it's configured to beep when it receives invalid input). It keeps reading and sees ;6D which are ordinary printing characters.

To see what escape sequence your terminal sends for a given key or key chord, press Ctrl+V then the key chord. Ctrl+V (^V) is a key binding in shells and other terminal applications that means “treat the next character literally”, and that causes the leading escape character in the escape sequence to be inserted literally, followed by the other characters in the escape sequence (which are ordinary printing characters). If you want to bind that key chord in your shell or other terminal application, you need to bind this escape sequence.

As I noted above, there are differences between terminals. There's a de facto standard for simple cases, but less so when modifiers are involved. Furthermore many terminals simply ignore certain modifiers on certain keys. For example, on Big Sur terminal, Ctrl+Shift+cursor key is indistinguishable from cursor key by default; this can be configured in the preferences (“Profiles” > “Keyboard”)). Iterm2 comes with more escape sequences out of the box including Ctrl+Shift+cursor key.

Further reading:

You must log in to answer this question.

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