# Backspace (BS)

> Move the cursor one column to the left.

- **Sequence:** `BS`
- **ECMA-48:** [§8.3.5 BS – Backspace, p. 34](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n47/mode/1up)
- **DEC STD 070:** [§5.4.4 Back Space, p. 5-63](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n317/mode/1up)
- **VT220:** [§4.2 Control Characters](https://vt100.net/docs/vt220-rm/chapter4.html#S4.2)
- **VT510:** [4.2 Control Characters](https://vt100.net/docs/vt510-rm/chapter4.html#S4.2)

Move the cursor one column to the left. Nothing is erased: the character
under the cursor stays where it is until something is written over it, which
is how a shell's line editor rubs out a character, with `BS`, a space and
another `BS`.

At the left margin, or the first column when there are no margins, the cursor
does not move. xterm's *reverse wraparound* mode (`CSI ? 45 h`) makes it
move to the end of the previous line instead; that mode is off by default and
not covered here.

If a wrap is pending, because the last thing written filled the last column,
the wrap is cancelled and the cursor moves left from the last column. xterm
handles BS as a one-column [`CursorBack`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/cursor.c#L121-L204), which clears
it.

## Validation

### BS-1: Overwrite the previous character

Input, one step per line:

```text
ABC
\b
X
```

Expected screen:

```text
|ABX__|
cursor 1,4
```

### BS-2: Nothing happens in the first column

Input, one step per line:

```text
\b\b
X
```

Expected screen:

```text
|X____|
cursor 1,2
```

### BS-3: Rubbing out a character

Input, one step per line:

```text
ABC
\b\s\b    # the line editor's erase
```

Expected screen:

```text
|AB___|
cursor 1,3
```

### BS-4: From a pending wrap

Input, one step per line:

```text
ABCDE     # fills the line; a wrap is pending
\b
X
```

Expected screen:

```text
|ABCXE|
cursor 1,5
```

### BS-5: Stops at the left margin

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

Input, one step per line:

```text
\e[?69h   # allow left and right margins
\e[3;5s   # margins at columns 3 and 5
\e[1;3H   # on the left margin
\b
X
```

Expected screen:

```text
|__X__|
```

libghostty-vt implements BS as a one-column [CUB](https://control-codes.page/csi/cub/index.html.md), and has the
same difference: the cursor moves past the left margin into column 2.
The VT510 manual says that at the left margin "no action occurs", and
esctest2's `test_BS_StopsAtLeftMargin` expects the cursor to stay put, as
xterm does.

---

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