# Erase Character (ECH)

> Blank n characters from the cursor rightwards, without moving anything.

- **Sequence:** `CSI Pn X`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.38 ECH – Erase Character, p. 41](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n54/mode/1up)
- **DEC STD 070:** [§5.11 Erase Character, p. 5-152](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n406/mode/1up)
- **VT510:** [ECH—Erase Character](https://vt100.net/docs/vt510-rm/ECH.html)

Erase the character under the cursor and the `Pn` − 1 after it. A `0` is
taken as `1`. Nothing else on the line moves, and neither does the cursor.
Asking for more characters than are left on the line erases to the end of
the line and stops; ECH never continues onto the next one.

Unlike [DCH](https://control-codes.page/csi/dch/index.html.md) and [ICH](https://control-codes.page/csi/ich/index.html.md), ECH ignores the margins. DEC
STD 070 says it "is not affected by the margins", and the VT510 manual that
it "works inside or outside the scrolling margins". The erased cells lose
their character attributes as well as their characters.

[EL](https://control-codes.page/csi/el/index.html.md) erases from the cursor to the end of the line in one go.

## Validation

### ECH-1: Erase one character

Input, one step per line:

```text
ABCDE
\e[1;2H
\e[X
```

Expected screen:

```text
|A_CDE|
cursor 1,2
```

### ECH-2: Erase three

Input, one step per line:

```text
ABCDE
\e[1;2H
\e[3X
```

Expected screen:

```text
|A___E|
```

### ECH-3: Stops at the end of the line

Input, one step per line:

```text
ABCDE\r\nFGHIJ
\e[1;4H
\e[99X
```

Expected screen:

```text
|ABC__|
|FGHIJ|
cursor 1,4
```

### ECH-4: Ignores the margins

Input, one step per line:

```text
abcdefg
\e[?69h   # allow left and right margins
\e[2;4s   # margins at columns 2 and 4
\e[1;3H
\e[4X     # runs past the right margin
```

Expected screen:

```text
|ab____g|
```

### ECH-5: Attributes are erased too

Input, one step per line:

```text
\e[1mABC\e[m
\e[1;2H
\e[X
```

Expected screen:

```text
|A_C__|
attr 1,1 bold
attr 1,2 plain
attr 1,3 bold
```

---

This is the Markdown version of <https://control-codes.page/csi/ech/>. 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>.
