# Repeat (REP)

> Print the character before it n more times.

- **Sequence:** `CSI Pn b`
- **Defaults:** Pn = 1
- **ECMA-48:** [§8.3.103 REP – Repeat, p. 55](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n68/mode/1up)
- **xterm:** [Functions using CSI](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)

Print the graphic character that came immediately before REP another `Pn`
times. It is a compression: `A\e[3b` puts four `A`s on the screen, exactly as
`AAAA` would, so the repeats wrap at the right margin and scroll at the bottom
margin like any other printed characters.

ECMA-48 defines the repeat only when the character just before REP is a
graphic character, including a space. If it is a control function, or part of
one, ECMA-48 leaves the effect undefined, so REP should come straight after
the character it repeats.

Neither DEC STD 070 nor the VT510 manual has REP. xterm implements it, and
lists it among its control sequences as "Repeat the preceding graphic
character".

## Validation

### REP-1: Repeat once

Input, one step per line:

```text
A\e[b
```

Expected screen:

```text
|AA___|
cursor 1,3
```

### REP-2: Repeat three times

Input, one step per line:

```text
A\e[3b
```

Expected screen:

```text
|AAAA_|
```

### REP-3: Wraps like printing

Input, one step per line:

```text
\e[1;4H
A\e[3b
```

Expected screen:

```text
|___AA|
|AA___|
cursor 2,3
```

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

Input, one step per line:

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

Expected screen:

```text
|_aaa_|
|_a___|
```

---

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