Skip to main content
ansicode

DCH — Delete Character (CSI Pn P)

Delete N cells at the cursor and shift the rest of the line left to fill the gap — the inverse of ICH.

Byte forms

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

\\x1b[\x1b[PnP
\\033[\033[PnP
\\e[\e[PnP
ESC [ESC [ Pn P
hex1b 5b <Pn> 50

Description

Delete Character. Final byte `P` (0x50) removes `Pn` cells starting at the cursor (default 1) and shifts every cell to the right of that range left by `Pn` columns; the `Pn` cells that appear at the right edge are blank (SP, 0x20) with the current SGR background. The cursor itself does not move. DCH is what `vim`/`emacs` emit when you backspace mid-line, what `less` uses to remove the bottom-of-screen prompt, and the primitive readline edits the prompt with. Pair with ICH (`\x1b[Pn @`). DCH stops at the right margin set by DECSTBM column-margins (if active) — cells past the margin are not pulled in. Terminfo cap: `dch1` (Pn=1) or `dch` (parameterised).

Spec citation: ECMA-48 §8.3.26 (DCH)

Examples

bash
# Print 'Hello world', move cursor to column 6, delete 6 cells.\nprintf 'Hello world\033[6G\033[6P'   # leaves 'Hello' followed by trailing blanks
python
import sys; sys.stdout.write('\x1b[3P')
go
fmt.Print("\x1b[3P")
javascript
process.stdout.write('\x1b[3P')
c
printf("\x1b[3P");

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