ESC (Escape) is ASCII code point 27 (0x1B), Unicode U+001B. It is a C0 control character that shifts the meaning of the bytes that follow it — the foundation of every ANSI/VT escape sequence used in terminals today. A single 0x1B followed by "[" (forming CSI) introduces commands for cursor movement, text color, scrolling, and screen clearing in xterm, GNOME Terminal, iTerm2, and virtually every modern emulator. Ctrl+[ emits it, which is why that keystroke functions as an Escape key alternative in vim. The byte is so central to terminal I/O that raw-mode parsers must always buffer after receiving 0x1B to determine whether it is a lone keypress or the start of a multi-byte sequence. UTF-8 encodes it as the single byte 0x1B; Unicode classifies it as Cc (Control) with the alias ESCAPE.
char esc = 27; // ASCII ESC (0x1B)char seq[] = {esc,'[','2','J','\0'}; // ANSI: clear screenfputs(seq, stdout); // write escape sequencefputs("Ready\n", stdout); // normal text resumes
ESC (ASCII 27) is the gateway to every ANSI terminal command. Colors, cursor movement, screen clearing — they all start with ESC followed by a command sequence. Without it, your terminal would be limited to plain, unformatted text.
They're commands that start with ESC[ (called CSI — Control Sequence Introducer). For example, ESC[31m makes text red, ESC[2J clears the screen, and ESC[H moves the cursor home. Every modern terminal emulator supports them.
Yes. If untrusted input containing ESC bytes reaches a terminal, it can rewrite what's displayed — hiding malicious commands in logs, spoofing prompts, or even injecting clipboard content in some emulators. Always sanitize control characters in logs and user-visible output.
It's not a shortcut — Ctrl+[ literally generates ASCII 27, the same byte as the Escape key. This is because control characters are calculated by subtracting 64 from the character's ASCII value: '[' is 91, and 91−64=27. Vim users rely on this daily.
In Vim, press Ctrl+V then Escape. In Bash, press Ctrl+V then Ctrl+[ (or Esc). In most programming strings, use the hex escape \x1b or the octal \033.
Use a regex that matches the escape sequence pattern. A common one is `/[[0-9;]*m/g` for colors, but for full coverage of all ANSI codes, you need a more complex pattern or a dedicated library like 'strip-ansi'.