ED
AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Standard
ED (Erase in Display / Erase in Page) is a CSI sequence that erases part or all of the visible screen.
Syntax
CSI Ps J ED — Erase in Display
Formal syntax
ED = 0x1b, "[", [ Ps ], "J" ; Ps = "0" | "1" | "2" ; (* default: 0 *)
Parameters
| Value | Meaning |
|---|---|
0 | Erase from cursor to end of display (default) |
1 | Erase from start of display to cursor |
2 | Erase the entire display |
Description
Per ECMA-48 §8.3.39, ED puts character positions into the erased state depending on the parameter value. "Erased state" means the positions are filled with the current background color (as set by SGR).
CSI 0 JorCSI J— Erases from the cursor position (inclusive) through the end of the screen. The cursor position does not change.CSI 1 J— Erases from the beginning of the screen through the cursor position (inclusive). The cursor position does not change.CSI 2 J— Erases the entire visible screen. The cursor position does not change. The scrollback buffer is not affected.
note
CSI 2 J clears the screen but does not move the cursor. To clear the screen and move home, use CSI 2 J followed by CSI H. This pair is what the clear command typically sends.
DECSED
The selective erase variant CSI ? Ps J (DECSED) erases only characters that were not written with the "protected" attribute set by DECSCA. Most applications use the non-selective form.
Examples
printf '\e[J' # Erase from cursor to end of screen
printf '\e[1J' # Erase from start of screen to cursor
printf '\e[2J' # Erase entire screen
printf '\e[2J\e[H' # Clear screen and move home
Specifications
| Specification | Section |
|---|---|
| ECMA-48 | — |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ✓ | 0.1.0 | Implemented via clear_screen with modes Above/Below/All |
| Bobcat | ✓ | 0.9.0 | Supported via TerminalCtrl library |
| contour | ✓ | v0.1.0 | |
| foot | ✓ | Yes | ED (J) modes 0, 1, 2 at csi.c:964-1005 |
| Ghostty | ✓ | v1.0.0 | |
| iTerm2 | ✓ | Yes | VT100CSI_ED token parsed with parameter handling for modes 0, 1, 2 via terminalEraseInDisplayBeforeCursor:afterCursor: |
| Kitty | ✓ | Yes | ED (CSI J) with modes 0/1/2/22 fully implemented in screen.c:2470-2532 |
| Konsole | ✓ | Yes | ED with parameters 0, 1, 2 implemented at src/Vt102Emulation.cpp:2020-2022 |
| mintty | ✓ | Yes | ED (CSI J) at line 3182-3192, supports parameters 0 (below), 1 (above), 2 (all) |
| mlterm | ✓ | rel-2_9_0 | Implemented at vt_parser.c:5651-5674 |
| PuTTY | ✓ | 0.45 | |
| Rio | ✓ | v0.0.3 | |
| rxvt-unicode | ✓ | 1.2 | |
| st | ✓ | 0.1 | |
| terminology | ✓ | v0.1.0 | |
| VT100 | ✓ | Yes | |
| VTE | ✓ | Yes | Fully implemented in vteseq.cc, supports modes 0, 1, 2 |
| WezTerm | ✓ | Yes | ED with parameters 0, 1, 2 implemented as EraseInDisplay::{EraseToEndOfDisplay, EraseToStartOfDisplay, EraseDisplay} |
| Windows Terminal | ✓ | Yes | Implemented in ITermDispatch.hpp:98 as EraseInDisplay with support for modes 0, 1, and 2 |
| xterm | ✓ | xterm-406 | |
| xterm.js | ✓ | 2.3.0 | |
| Multiplexers | |||
| cy | ✓ | v0.1.0 | |
| GNU Screen | ✓ | v.4.2.0 | Supports modes 0, 1, 2 only |
| tmux | ✓ | 1.6 | ED (CSI J) with parameters 0, 1, 2 all implemented |
| tuios | ✓ | v0.0.15 | |
| Zellij | ✓ | v0.1.0-alpha | |
See also
- ED 3 — Erase Scrollback Buffer — XTerm extension to clear scrollback
- EL — Erase in Line — Erase part of the current line
- ECH — Erase Character — Erase a specific number of characters