# Insert Character (ICH)

> Insert n blank cells at the cursor, shifting the rest of the line right.

- **Sequence:** `CSI Pn @`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.64 ICH – Insert Character, p. 46](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n59/mode/1up)
- **DEC STD 070:** [§5.11 Insert Character, p. 5-142](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n396/mode/1up)
- **VT220:** [§4.11 Editing](https://vt100.net/docs/vt220-rm/chapter4.html#S4.11)
- **VT510:** [ICH—Insert Character](https://vt100.net/docs/vt510-rm/ICH.html)

Insert `Pn` blank cells at the cursor. The cursor's cell and everything to
its right moves right by `Pn`, and whatever is pushed past the right margin
is lost. A `0` is taken as `1`. The cursor does not move.

With left and right margins set, only the part of the line inside them
shifts, and nothing happens at all if the cursor is outside them.

[DCH](https://control-codes.page/csi/dch/index.html.md) is the reverse, deleting cells and pulling the rest of the line left.

## Validation

### ICH-1: Insert two

Input, one step per line:

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

Expected screen:

```text
|A__BCD|
cursor 1,2
```

### ICH-2: Then write into the gap

Input, one step per line:

```text
ABCDE
\e[1;2H
\e[2@
XY
```

Expected screen:

```text
|AXYBCD|
```

### ICH-3: Inside a right margin

Input, one step per line:

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

Expected screen:

```text
|A_BCEF|
```

---

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