# Delete Character (DCH)

> Delete n characters at the cursor, pulling the rest of the line left.

- **Sequence:** `CSI Pn P`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.26 DCH – Delete Character, p. 38](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n51/mode/1up)
- **DEC STD 070:** [§5.11 Delete Character, p. 5-144](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n398/mode/1up)
- **VT220:** [§4.11 Editing](https://vt100.net/docs/vt220-rm/chapter4.html#S4.11)
- **VT510:** [DCH—Delete Character](https://vt100.net/docs/vt510-rm/DCH.html)

Delete `Pn` characters, starting with the one under the cursor. The rest of
the line, up to the right margin, moves left to close the gap, and blank
cells appear at the right margin. A `0` is taken as `1`, and asking for more
characters than there are between the cursor and the right margin deletes
only those. The cursor does not move.

Only the cursor's line is affected, and only the part of it between the left
and right margins. If the cursor is outside those margins, DCH does nothing.
The top and bottom margins do not matter: DCH works on any line. Character
attributes move with the characters, and the VT510 manual says the blanks
added at the right margin have none. Insert/replace mode makes no difference.

[ICH](https://control-codes.page/csi/ich/index.html.md) is the reverse. [ECH](https://control-codes.page/csi/ech/index.html.md) blanks characters without
moving the rest of the line.

## Validation

### DCH-1: Delete one character

Input, one step per line:

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

Expected screen:

```text
|ACDE__|
cursor 1,2
```

### DCH-2: Delete two

Input, one step per line:

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

Expected screen:

```text
|ADE___|
```

### DCH-3: More characters than there are

Input, one step per line:

```text
ABCDE
\e[1;2H
\e[99P
```

Expected screen:

```text
|A_____|
```

### DCH-4: Inside left and right margins

Input, one step per line:

```text
abcde
\e[?69h   # allow left and right margins
\e[2;4s   # margins at columns 2 and 4
\e[1;3H
\e[P
```

Expected screen:

```text
|abd_e|
```

### DCH-5: Nothing happens outside the margins

Input, one step per line:

```text
abcde
\e[?69h   # allow left and right margins
\e[2;4s   # margins at columns 2 and 4
\e[1;1H   # left of them
\e[99P
```

Expected screen:

```text
|abcde|
```

---

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