Skip to main content
ansicode

DECSED / DECSEL — Selective erase display / line (CSI ? Ps J / CSI ? Ps K)

Erase only the unprotected cells in the display (DECSED) or current line (DECSEL) — the private-mode siblings of ED / EL.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b[?<Ps>J (DECSED) \x1b[?<Ps>K (DECSEL)
\\033[\033[?2J / \033[?2K
\\e[\e[?2J / \e[?2K
ESC [ESC [ ? Ps J / ESC [ ? Ps K
hex1b 5b 3f ... 4a / 1b 5b 3f ... 4b

Description

Identical to ED (\x1b[<Ps>J) and EL (\x1b[<Ps>K) in scope (Ps=0 cursor→end, 1 start→cursor, 2 entire region), but skips cells marked as protected by DECSCA (\x1b[<Ps>"q). DECSCA tags individual character cells as protected (Ps=1) or unprotected (Ps=0 / 2); DECSED and DECSEL are the only erase primitives that honour that tag. Useful for forms — paint immutable labels with DECSCA-protected attribute on, accept user input in unprotected cells, and \x1b[?2K clears only the entry fields without disturbing labels. Outside the forms / data-entry use-case these sequences are vanishingly rare; many modern emulators (alacritty, wezterm, ghostty) treat them as plain ED / EL because they don't track DECSCA at all. Don't reach for these in greenfield code unless you're actually implementing a VT220-style data-entry form.

Spec citation: DEC STD 070 (DECSED / DECSEL) / DEC VT510 RM

Parameters

Ps0 (default) erase cursor → end of region · 1 start of region → cursor · 2 entire region. Protected cells (DECSCA) are skipped.

Examples

bash
# Erase only unprotected cells on the current line:\nprintf '\033[?2K'
python
import sys\n# Selective ED 2 — keep DECSCA-protected labels intact:\nsys.stdout.write('\x1b[?2J')
go
fmt.Print("\x1b[?0K")   // selective EL: cursor to end of line
javascript
process.stdout.write('\x1b[?2K')   // selective EL: whole line, skip protected cells
c
printf("\x1b[?1J");  // selective ED: top of screen to cursor

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
partial
iTerm2
partial
Windows Terminal
no
cmd.exe / ConPTY
no
kitty
no
alacritty
no
WezTerm
no
Ghostty
no
GNOME Terminal
partial
Konsole
partial
tmux
yes
GNU screen
yes

Related sequences

In the family cookbook

CSI cookbook · 3. Erase — ED `J` and EL `K`