DCH Delete Character
Delete n characters at the cursor, pulling the rest of the line left.
CSI Pn P
- Defaults
- Pn = 1
- ECMA-48
- §8.3.26 DCH – Delete Character, p. 38
- DEC STD 070
- §5.11 Delete Character, p. 5-144
- VT220
- §4.11 Editing
- VT510
- DCH—Delete Character
Delete Pn characters, starting with the one under the cursor. The rest of the line, up to the right margin, moves left to close the gap, and blank cells appear at the right margin. A 0 is taken as 1, and asking for more characters than there are between the cursor and the right margin deletes only those. The cursor does not move.
Only the cursor’s line is affected, and only the part of it between the left and right margins. If the cursor is outside those margins, DCH does nothing. The top and bottom margins do not matter: DCH works on any line. Character attributes move with the characters, and the VT510 manual says the blanks added at the right margin have none. Insert/replace mode makes no difference.
ICH is the reverse. ECH blanks characters without moving the rest of the line.
Support
| Terminal | Version | Support | Notes |
|---|---|---|---|
| VT220 | manual, 2nd ed., 1984 | Yes | §4.11 Editing |
| VT510 | manual, 1st ed., 1993 | Yes | DCH |
| xterm | patch 412, xterm-411a | Yes | |
| libghostty-vt | 0f171f6 | Yes | |
| kitty | 0.49.1, run in a VM | Partly | fails DCH-4 of the 4 cases that show it working |
| foot | 1.28.0, run in a VM | Partly | fails DCH-4 of the 4 cases that show it working |
| pyte | 0.8.2, run as a library | Partly | fails DCH-4 of the 4 cases that show it working |
| xterm.js headless | 6.0.0, run as a library | Partly | fails DCH-4 of the 4 cases that show it working |
| alacritty_terminal | 0.26.0, run as a library | Partly | fails DCH-3, DCH-4 of the 4 cases that show it working |
| ConEmu | build 230724, its documentation | Yes | lists ESC [ n P: ANSI escape codes |
| rxvt-unicode | 9.31, run in a VM | Partly | fails DCH-4 of the 4 cases that show it working |
| VTE | 0.84.1, run as a library | Yes | passes the 4 cases that show it working |
Validation
DCH-1: Delete one character
ABCDE
\e[1;2H
\e[P
|ACDE__|
cursor 1,2
DCH-2: Delete two
ABCDE
\e[1;2H
\e[2P
|ADE___|
DCH-3: More characters than there are
ABCDE
\e[1;2H
\e[99P
|A_____|
DCH-4: Inside left and right margins
abcde
\e[?69h # allow left and right margins
\e[2;4s # margins at columns 2 and 4
\e[1;3H
\e[P
|abd_e|
DCH-5: Nothing happens outside the margins
abcde
\e[?69h # allow left and right margins
\e[2;4s # margins at columns 2 and 4
\e[1;1H # left of them
\e[99P
|abcde|