ED Erase in Display
Erase part or all of the screen.
CSI Ps J
- Defaults
- Ps = 0
- ECMA-48
- §8.3.39 ED – Erase in Page, p. 41
- DEC STD 070
- §5.11 Erase in Display, p. 5-156
- VT220
- §4.12 Erasing
- VT510
- ED—Erase in Display
Erase some of the screen, chosen by Ps:
Ps | Erases |
|---|---|
0 | from the cursor to the end of the screen, the cursor’s cell included |
1 | from the start of the screen to the cursor, the cursor’s cell included |
2 | the whole screen |
3 | the scrollback, which is not on the screen (an xterm extension) |
The cursor does not move. Erasing ignores the margins; it is the screen that is erased, not the scrolling region.
An erased cell takes the current background color, set with SGR, rather than the default. That is background color erase, and is why programs reset SGR before clearing the screen.
Support
| Terminal | Version | Support | Notes |
|---|---|---|---|
| VT220 | manual, 2nd ed., 1984 | Yes | §4.12 Erasing; 0 to 2, as DEC defined it; 3 is xterm’s |
| VT510 | manual, 1st ed., 1993 | Yes | ED; 0 to 2, as DEC defined it; 3 is xterm’s |
| xterm | patch 412, xterm-411a | Yes | 3 follows the eraseSavedLines resource, on by default |
| libghostty-vt | 0f171f6 | Yes | |
| kitty | 0.49.1, run in a VM | Yes | passes the 3 cases that show it working |
| foot | 1.28.0, run in a VM | Yes | passes the 3 cases that show it working |
| pyte | 0.8.2, run as a library | Yes | passes the 3 cases that show it working |
| xterm.js headless | 6.0.0, run as a library | Yes | passes the 3 cases that show it working |
| alacritty_terminal | 0.26.0, run as a library | Partly | fails ED-2 of the 3 cases that show it working |
| ConEmu | build 230724, its documentation | Yes | its list has 2 also move the cursor to the upper-left corner; ANSI escape codes |
| rxvt-unicode | 9.31, run in a VM | Yes | passes the 3 cases that show it working |
| VTE | 0.84.1, run as a library | Yes | passes the 3 cases that show it working |
Validation
ED-1: Below
\e#8 # fill with E
\e[2;2H
\e[J
|EEEE|
|E___|
|____|
cursor 2,2
ED-2: Above
\e#8 # fill with E
\e[2;2H
\e[1J
|____|
|__EE|
|EEEE|
cursor 2,2
ED-3: Everything
\e#8 # fill with E
\e[2;2H
\e[2J
|____|
|____|
|____|
cursor 2,2
ED-4: With a background color
\e[44m # blue background
\e[2J
|____|
|____|
attr 1,1 bg=4
attr 2,4 bg=4