# Escape (ESC)

> Begin an escape sequence, abandoning any sequence already in progress.

- **Sequence:** `ESC`
- **ECMA-48:** [§8.3.48 ESC – Escape, p. 43](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n56/mode/1up)
- **DEC STD 070:** [§3.5.1.2.3 Escape, p. 3-19](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n123/mode/1up)
- **VT510:** [4.2 Control Characters](https://vt100.net/docs/vt510-rm/chapter4.html#S4.2)

ESC begins an escape sequence: it "causes the meanings of a limited number of
bit combinations following it in the data stream to be changed", in
ECMA-48's words, which leaves the rules for what may follow to ECMA-35. Every
multi-byte sequence on this site starts with it, including the control
sequences, whose introducer CSI is written `ESC [` in a 7-bit stream.

An ESC that arrives while a sequence is still in progress abandons that
sequence and starts a new one. DEC STD 070 says "the sequence is canceled and
a new sequence begins with that ESC", and the VT510 manual
([§4.3.5](https://vt100.net/docs/vt510-rm/chapter4.html#S4.3.5)) that ESC can
be sent "to cancel a sequence in progress and begin a new sequence". Unlike
[CAN](https://control-codes.page/c0/can/index.html.md) and [SUB](https://control-codes.page/c0/sub/index.html.md), the ESC is not lost: it is the start of
whatever comes next.

xterm's parser table sends ESC to [`CASE_ESC`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/VTPrsTbl.c#L185-L189) in
the ground state as it does in the middle of a sequence.

## Validation

### ESC-1: Abandons a control sequence, and starts another

Input, one step per line:

```text
A
\e[3      # CUF, unfinished
\e[2;1H   # a new CUP
X
```

Expected screen:

```text
|A____|
|X____|
```

### ESC-2: Abandons an escape sequence

Input, one step per line:

```text
\e#       # DECALN, unfinished
\e[2;2H
X
```

Expected screen:

```text
|_____|
|_X___|
```

---

This is the Markdown version of <https://control-codes.page/c0/esc/>. On that page every validation case runs live in libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly.

The validation cases are written in the notation described in <https://control-codes.page/notation/index.html.md>.
