Skip to main content
ansicode

ECH — Erase Character (CSI Pn X)

Erase N cells in place at the cursor — same shape as DCH but the rest of the line does NOT shift left.

Byte forms

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

\\x1b[\x1b[PnX
\\033[\033[PnX
\\e[\e[PnX
ESC [ESC [ Pn X
hex1b 5b <Pn> 58

Description

Erase Character. Final byte `X` (0x58) replaces `Pn` cells starting at the cursor (default 1) with blank (SP, 0x20) cells carrying the current SGR background. The cursor does not move and the rest of the line is NOT shifted — this is the key distinction from DCH (`\x1b[Pn P`). Used when an app wants to clear a fixed-width field (input prompt, table cell, progress bar segment) without affecting surrounding content. ECH is bounded by the right margin (DECSTBM column-margins, if active); cells past the right margin are not touched. Terminfo cap: `ech` (parameterised; no `ech1` because the no-shift semantics make the parameterised form universally needed).

Spec citation: ECMA-48 §8.3.38 (ECH)

Examples

bash
# Print a 10-char field, position at col 1, erase 5 chars in place (rest of line preserved).\nprintf '0123456789\033[1G\033[5X'
python
import sys; sys.stdout.write('\x1b[5X')   # clear 5 cells in place
go
fmt.Print("\x1b[5X")
javascript
process.stdout.write('\x1b[5X')
c
printf("\x1b[5X");

Terminal support

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

Related sequences

In the family cookbook

CSI cookbook · 6. Insert / delete / cursor shape — IL / DL / ICH / DCH / ECH + DECSCUSR