# Line Editing Mode (VEM)

> Which way lines move when one is inserted or deleted.

- **Sequence:** `CSI 7 h`
- **ECMA-48:** [§7.2.19 VEM – Line Editing Mode, p. 25](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n38/mode/1up)
- **DEC STD 070:** [§5.10.1.3 Modes That Cannot Be Changed, p. 5-134](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n388/mode/1up)

Mode 7 decides which lines move when a line is inserted with [IL](https://control-codes.page/csi/il/index.html.md)
or deleted with [DL](https://control-codes.page/csi/dl/index.html.md). DEC STD 070 calls it Vertical Editing Mode.

| State | ECMA-48 calls it | Meaning |
| --- | --- | --- |
| Reset, `CSI 7 l` | FOLLOWING | the active line and those below it move down for an insertion, and up to close a deletion |
| Set, `CSI 7 h` | PRECEDING | the lines above move up for an insertion, and down to close a deletion |

[DEC STD 070 §5.10.1.3, p. 5-134](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n388/mode/1up) lists it among the X3.64 modes a DEC terminal may treat as fixed,
as reset. The VT510 manual's [table of modes for DECRPM](https://vt100.net/docs/vt510-rm/DECRPM.html) marks it as always reset. That is the way IL and DL work in xterm and libghostty-vt.

xterm ignores `CSI 7 h` and `CSI 7 l` ([`ansi_modes`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/charproc.c#L7399-L7424) handles only modes 2,
4, 12 and 20), and [DECRQM](https://control-codes.page/csi/decrqm/index.html.md) reports the mode as permanently
reset, `4` ([`do_ansi_rqm`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L5408-L5463)). libghostty-vt ignores it too, but does not recognize the
number, so it answers DECRQM with `0`. Both DECRQM cases are known
differences.

## Validation

### VEM-1: Reported as permanently reset

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

Input, one step per line:

```text
\e[7$p
```

Expected screen:

```text
|_____|
reply \e[7;4$y
```

### VEM-2: Even after it is set

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

Input, one step per line:

```text
\e[7h
\e[7$p
```

Expected screen:

```text
|_____|
reply \e[7;4$y
```

### VEM-3: IL still pushes the lines below down

Input, one step per line:

```text
A\r\n
B\r\n
C
\e[7h      # ignored
\e[2;1H
\e[L
```

Expected screen:

```text
|A__|
|___|
|B__|
```

---

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