# Autowrap Mode (DECAWM)

> Choose whether text reaching the right margin continues on the next line.

- **Sequence:** `CSI ? 7 h`
- **DEC STD 070:** [§D.6.2 Set/Reset Auto Wrap Mode, p. D-15](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n1201/mode/1up)
- **VT510:** [DECAWM—Autowrap Mode](https://vt100.net/docs/vt510-rm/DECAWM.html)

`CSI ? 7 h` sets autowrap mode and `CSI ? 7 l` resets it.

With it set, text that reaches the right margin carries on at the start of
the next line, scrolling if the cursor is on the bottom margin. Writing a
character into the last column does not move the cursor on at once: DEC STD
070 says a *Last Column Flag* is set instead, and the next character printed
first moves to the next line. This site calls that a pending wrap.

With it reset, the cursor stays in the last column, and each further
character overwrites the one there. The VT510 manual says they "replace
characters already on the page".

Autowrap affects only printed characters. Cursor movement and control
characters stop at the margin as they always do.

DEC STD 070 describes autowrap in an appendix of *documented exceptions*
([§D.6.1, p. D-13](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n1199/mode/1up)), not in its main text. Its change
history for the Character Cell Display section records that autowrap was
"an exception to Level 1", and that all references to it and to the Last
Column Flag were removed from that section. The appendix also lists the
controls that should clear a pending wrap, among them resetting autowrap
mode, and warns that "existing products vary widely" in this.

The VT510 manual gives the default as no autowrap. xterm turns it on by
default ([`autoWrap`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/charproc.c#L423)), and so does libghostty-vt.

## Validation

### DECAWM-1: On, the next character wraps

Input, one step per line:

```text
\e[?7h
ABCDE     # fills the line; a wrap is pending
F
```

Expected screen:

```text
|ABCDE|
|F____|
cursor 2,2
```

### DECAWM-2: Off, the last column is overwritten

Input, one step per line:

```text
\e[?7l
ABCDE
FG
```

Expected screen:

```text
|ABCDG|
|_____|
cursor 1,5
```

### DECAWM-3: Turned off with a wrap pending

Input, one step per line:

```text
ABCDE     # a wrap is pending
\e[?7l
F
```

Expected screen:

```text
|ABCDF|
|_____|
```

### DECAWM-4: On to begin with

Input, one step per line:

```text
\e[?7$p   # DECRQM: is mode 7 set?
```

Expected screen:

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

---

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