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[PnX\033[PnX\e[PnXESC [ Pn X1b 5b <Pn> 58Description
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
# Print a 10-char field, position at col 1, erase 5 chars in place (rest of line preserved).\nprintf '0123456789\033[1G\033[5X'import sys; sys.stdout.write('\x1b[5X') # clear 5 cells in placefmt.Print("\x1b[5X")process.stdout.write('\x1b[5X')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
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | yes | yes | yes | yes | partial | yes | yes | yes | yes | yes | yes | no | no |
Related sequences
In the family cookbook
CSI cookbook · 6. Insert / delete / cursor shape — IL / DL / ICH / DCH / ECH + DECSCUSR