# Cursor Down (CUD)

> Move the cursor down n lines.

- **Sequence:** `CSI Pn B`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.19 CUD – Cursor Down, p. 36](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n49/mode/1up)
- **DEC STD 070:** [§5.4.4 Cursor Down, p. 5-43](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n297/mode/1up)
- **VT510:** [CUD—Cursor Down](https://vt100.net/docs/vt510-rm/CUD.html)

Move the cursor `Pn` lines down, keeping its column. A `0` is taken as `1`.

The cursor stops at the bottom margin if it started at or above it. A cursor
already below the bottom margin stops at the last line instead. CUD never
scrolls, which is the difference between it and a [line feed](https://control-codes.page/c0/lf/index.html.md): at
the bottom margin a line feed scrolls the region up, and CUD stays put.

Moving the cursor cancels any pending wrap. DEC STD 070 calls the pending
wrap the *Last Column Flag*, and its appendix on autowrap lists this among
the controls that should reset it
([§D.6.1, p. D-13](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n1199/mode/1up)); xterm clears it in
[`CursorDown`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/cursor.c#L251-L263), and libghostty-vt does the same.

[CUU](https://control-codes.page/csi/cuu/index.html.md) goes the other way, and [CNL](https://control-codes.page/csi/cnl/index.html.md) moves down and
returns to the left margin as well.

## Validation

### CUD-1: Down one line

Input, one step per line:

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

Expected screen:

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

### CUD-2: Down n lines, stopping at the last line

Input, one step per line:

```text
\e[1;2H
\e[9B
X
```

Expected screen:

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

### CUD-3: Stops at the bottom margin, without scrolling

Input, one step per line:

```text
A
\e[1;3r   # region is lines 1 to 3
\e[2;1H
\e[9B
X
```

Expected screen:

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

### CUD-4: Below the bottom margin

Input, one step per line:

```text
\e[1;2r   # region is lines 1 and 2
\e[3;1H   # below it
\e[9B
X
```

Expected screen:

```text
|_____|
|_____|
|_____|
|X____|
```

### CUD-5: From a pending wrap

Input, one step per line:

```text
ABCDE     # fills the line; a wrap is pending
\e[B
X
```

Expected screen:

```text
|ABCDE|
|____X|
|_____|
```

---

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