^[control-codes
live in libghostty-vt

Control sequences

DCH Delete Character

View as Markdown

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

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984Yes§4.11 Editing
VT510manual, 1st ed., 1993YesDCH
xtermpatch 412, xterm-411aYes
libghostty-vt0f171f6Yes
kitty0.49.1, run in a VMPartlyfails DCH-4 of the 4 cases that show it working
foot1.28.0, run in a VMPartlyfails DCH-4 of the 4 cases that show it working
pyte0.8.2, run as a libraryPartlyfails DCH-4 of the 4 cases that show it working
xterm.js headless6.0.0, run as a libraryPartlyfails DCH-4 of the 4 cases that show it working
alacritty_terminal0.26.0, run as a libraryPartlyfails DCH-3, DCH-4 of the 4 cases that show it working
ConEmubuild 230724, its documentationYeslists ESC [ n P: ANSI escape codes
rxvt-unicode9.31, run in a VMPartlyfails DCH-4 of the 4 cases that show it working
VTE0.84.1, run as a libraryYespasses 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|
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.