# Character Position Forward (HPR)

> Move the cursor right n columns.

- **Sequence:** `CSI Pn a`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.59 HPR – Character Position Forward, p. 45](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n58/mode/1up)
- **VT510:** [HPR—Horizontal Position Relative](https://vt100.net/docs/vt510-rm/HPR.html)

Move the cursor `Pn` columns to the right, on the line it is on. A `0` is
taken as `1`. The VT510 manual says that an attempt to move past the last
position on the line stops at the last position.

It is a relative move, so origin mode makes no difference to it: the cursor
moves `Pn` columns from wherever it is.

ECMA-48 names it for the *data* component, which a terminal does not have
apart from its screen (§6, p. 14). Its counterpart going left is
[HPB](https://control-codes.page/csi/hpb/index.html.md), and the absolute form is [HPA](https://control-codes.page/csi/hpa/index.html.md). The VT510
manual's one-line summary of HPR is a copying error, as it is for HPA; the
description beneath it is the right one.

## Validation

### HPR-1: One column by default

Input, one step per line:

```text
AB
\e[a
X
```

Expected screen:

```text
|AB_X_|
```

### HPR-2: n columns

Input, one step per line:

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

Expected screen:

```text
|_____|
|___X_|
```

### HPR-3: Stops at the last column

Input, one step per line:

```text
\e[2;2H
\e[99a
X
```

Expected screen:

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

### HPR-4: The same in origin mode

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
\e[2;4r   # region is lines 2 to 4
\e[?69h   # allow left and right margins
\e[2;7s   # margins at columns 2 and 7
\e[?6h    # origin mode
\e[2;2H   # line 3, column 3 of the screen
X
\e[2a
Y
\e[?6l
```

Expected screen:

```text
|________|
|________|
|__X__Y__|
|________|
```

The `Y` should be two columns past the cell after `X`, on the same line,
which is what esctest2's `test_HPR_IgnoresOriginMode` checks. libghostty-vt
moves it down as well. HPR there is
`setCursorPos(current line + 1, current column + 1 + Pn)`, and in origin mode
`setCursorPos` adds the margins to both, so the line the cursor is on is
offset by the top margin and the column by the left margin.

---

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