ICH/DCH/ECH
ICH (Insert Character), DCH (Delete Character), and ECH (Erase Character) are CSI sequences that insert, delete, or erase characters at the cursor position within the current line.
Syntax
CSI Pn @ ICH — Insert Character
CSI Pn P DCH — Delete Character
CSI Pn X ECH — Erase Character
ICH = 0x1b, "[", [ Pn ], "@" ;
DCH = 0x1b, "[", [ Pn ], "P" ;
ECH = 0x1b, "[", [ Pn ], "X" ;
Pn = digit, { digit } ; (* default: 1 *)
digit = "0" | "1" | "2" | "3" | "4"
| "5" | "6" | "7" | "8" | "9" ;Parameters
| Parameter | Description | Default |
|---|---|---|
Pn | Number of characters to insert/delete/erase | 1 |
Description
These three operations affect characters on the current line only. They do not cross line boundaries.
ICH — Insert Character (CSI Pn @)
Per ECMA-48 §8.3.64, ICH inserts Pn blank characters at the cursor position. Existing characters from the cursor rightward are shifted to the right; characters pushed past the right margin are lost. The cursor position does not change.
DCH — Delete Character (CSI Pn P)
Per ECMA-48 §8.3.26, DCH removes Pn characters starting at the cursor position. Characters to the right are shifted left to fill the gap, and blank characters are inserted at the right end of the line.
ECH — Erase Character (CSI Pn X)
Per ECMA-48 §8.3.38, ECH replaces Pn characters starting at the cursor position with blank (erased) characters. Unlike DCH, no shifting occurs — surrounding characters are not moved. The cursor position does not change.
The key distinction: ICH and DCH shift characters on the line (insert/delete semantics), while ECH overwrites characters in place (erase semantics).
Examples
printf '\e[2@' # Insert 2 blank characters at cursor
printf '\e[3P' # Delete 3 characters at cursor
printf '\e[5X' # Erase 5 characters at cursor (no shift)
Specifications
| Specification | Section |
|---|---|
| ECMA-48 | — |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ✓ | 0.1.0 | Implemented via insert_blank/delete_chars/erase_chars methods |
| Bobcat | ✓ | 0.9.0 | Supported via TerminalCtrl library |
| contour | ✓ | v0.1.0 | |
| foot | ✓ | Yes | ICH (@) at csi.c:1116-1142, DCH (P) at csi.c:1087-1114, ECH (X) at csi.c:1158-1170 |
| Ghostty | ✓ | v1.0.0 | |
| iTerm2 | ✓ | Yes | VT100CSI_ICH, XTERMCC_DELCH, and ANSICSI_ECH tokens parsed and executed via terminalInsertEmptyCharsAtCursor, terminalDeleteCharactersAtCursor, and terminalEraseCharactersAfterCursor |
| Kitty | ✓ | Yes | ICH/DCH/ECH (CSI @/P/X) fully implemented in vt-parser.c:1188-1247 |
| Konsole | ✓ | Yes | ICH (@), DCH (P), ECH (X) implemented at src/Vt102Emulation.cpp:2123,2135,2138 |
| mintty | ✓ | Yes | ICH (CSI @) at line 3237-3238, DCH (CSI P) at line 3239-3240, ECH (CSI X) at line 3204-3220 |
| mlterm | ✓ | rel-2_9_0 | ICH at vt_parser.c:5557-5565, DCH at 5701-5708, ECH at 5753-5760 |
| PuTTY | ✓ | 0.45 | |
| Rio | ✓ | v0.0.3 | |
| rxvt-unicode | ✓ | 1.2 | |
| st | ✓ | 0.1 | |
| terminology | ✓ | v0.1.0 | |
| VT100 | ✗ | No | |
| VTE | ✓ | Yes | Fully implemented in vteseq.cc as ICH/DCH/ECH handlers |
| WezTerm | ✓ | Yes | ICH (InsertCharacter), DCH (DeleteCharacter), ECH (EraseCharacter) implemented as Edit::InsertCharacter/DeleteCharacter/EraseCharacter |
| Windows Terminal | ✓ | Yes | ICH at ITermDispatch.hpp:54, DCH at line 55, ECH at line 100. All three character edit operations implemented. |
| xterm | ✓ | xterm-406 | |
| xterm.js | ✓ | 2.3.0 | |
| Multiplexers | |||
| cy | ✓ | v0.1.0 | |
| GNU Screen | ✓ | v.4.2.0 | |
| tmux | ✓ | 1.8 | ICH (CSI @), DCH (CSI P) in 1.6; ECH (CSI X) added in 1.8 |
| tuios | ✓ | v0.0.15 | |
| Zellij | ✓ | v0.10.0 | ICH added in v0.10.0, DCH and ECH present since v0.1.0-alpha |
See also
- IL/DL — Insert/Delete Lines — Line-level insert/delete
- ED — Erase in Display — Erase regions of the screen
- EL — Erase in Line — Erase part of the current line