# Cursor Forward (CUF)

> Move the cursor right n columns.

- **Sequence:** `CSI Pn C`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.20 CUF – Cursor Right, p. 36](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n49/mode/1up)
- **DEC STD 070:** [§5.4.4 Cursor Forward, p. 5-45](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n299/mode/1up)
- **VT510:** [CUF—Cursor Forward](https://vt100.net/docs/vt510-rm/CUF.html)

Move the cursor `Pn` columns to the right. A `0` is taken as `1`. The cells
passed over are left as they are.

The cursor stops at the right margin if it started at or left of it, and at
the last column if it started right of the right margin. It never wraps onto
the next line and never scrolls.

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
[`CursorForward`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/cursor.c#L211-L243), and libghostty-vt does the same. A cursor in the last column with
a wrap pending stays in that column, and the next character overwrites the
last cell rather than starting a new line.

[CUB](https://control-codes.page/csi/cub/index.html.md) goes the other way.

## Validation

### CUF-1: Right n columns, leaving the cells alone

Input, one step per line:

```text
ABCDE
\r
\e[2C
X
```

Expected screen:

```text
|ABXDE|
```

### CUF-2: Stops at the last column

Input, one step per line:

```text
\e[99C
X
```

Expected screen:

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

### CUF-3: Stops at the right margin

Input, one step per line:

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

Expected screen:

```text
|___X_|
```

### CUF-4: Right of the right margin

Input, one step per line:

```text
\e[?69h   # allow left and right margins
\e[1;3s   # margins at columns 1 and 3
\e[1;4H   # right of them
\e[9C
X
```

Expected screen:

```text
|____X|
```

### CUF-5: From a pending wrap

Input, one step per line:

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

Expected screen:

```text
|ABCDX|
|_____|
```

---

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