Strovent SystemsSign in
Reference

Keys and key codes

What the arrow, function, Home, End and Ctrl keys send, and why Backspace and Delete confuse people.

In a VT session the keys are sent as bytes. Special keys send escape sequences.

Typing characters

Cursor keys

Normal mode          Application mode
Up      ESC [ A      ESC O A
Down    ESC [ B      ESC O B
Right   ESC [ C      ESC O C
Left    ESC [ D      ESC O D

Full-screen programs such as vim and less switch to application mode. Both are handled by a correct terminal. If arrow keys print ^[[A in a program, the terminal type is probably wrong.

Home        ESC [ H  (or ESC [ 1 ~)
End         ESC [ F  (or ESC [ 4 ~)
Insert      ESC [ 2 ~
Delete      ESC [ 3 ~
Page Up     ESC [ 5 ~
Page Down   ESC [ 6 ~

Function keys (xterm)

F1  ESC O P      F2  ESC O Q      F3  ESC O R      F4  ESC O S
F5  ESC [ 15 ~   F6  ESC [ 17 ~   F7  ESC [ 18 ~   F8  ESC [ 19 ~
F9  ESC [ 20 ~   F10 ESC [ 21 ~   F11 ESC [ 23 ~   F12 ESC [ 24 ~

Linux console and some other terminal types use different sequences for the same keys. That is why the terminal type has to match what you tell the host.

Backspace and Delete

Hosts disagree about which byte erases a character:

  • DEL (7F) is the common choice today.
  • Backspace (08, also Ctrl+H) was the traditional one.

If Backspace prints ^H, or Delete prints ~, the terminal and the host disagree. Check the Backspace sends setting of your client. On the host, stty erase ^? selects DEL and stty erase ^H selects BS.

Hardware keyboards and F-keys

A phone or tablet keyboard may lack Esc, F1 to F12 or Ctrl. Use the client's key bar or on-screen keys for them. Esc matters in vim, and Ctrl+C interrupts a stuck command.

Spotted a mistake? Email [email protected].