Skip to main content
ansicode

DECSTR — Soft terminal reset

Reset DEC private modes and SGR to defaults WITHOUT clearing the screen or scrollback.

Byte forms

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

\\x1b[\x1b[!p
\\033[\033[!p
\\e[\e[!p
ESC [ESC [ ! p
hex1b 5b 21 70

Description

DEC Soft Terminal Reset (DECSTR). Standard CSI with an intermediate ! (0x21) before the final p (0x70): \x1b[!p. xterm-ctlseqs §DECSTR documents the exact reset set — SGR (colour + bold + italic + underline + reverse + blink + strikethrough), DECAWM auto-wrap (?7), DECOM origin mode (?6), IRM insert / replace mode, keyboard application / cursor-key modes, character sets G0–G3, DECSTBM scrolling region (top = 1, bottom = visible height), DECSCUSR cursor style (back to user default), and several other DEC private modes. It explicitly does NOT clear the screen, does NOT touch the scrollback buffer, and does NOT exit the alt-screen — that's what makes it the "soft" reset, the surgical complement of RIS.

Portability — universal across xterm, iTerm2, kitty, alacritty, wezterm, gnome-terminal, Konsole, Ghostty, Linux console, Windows Terminal, and ConPTY 1809+. Windows legacy cmd.exe (pre-ConPTY) ignored DECSTR entirely. The canonical recovery scenario: a TUI crashed in the middle of vim or htop with reverse-video active, auto-wrap turned off, the scrolling region restricted to lines 5–20, the cursor hidden, and DECSCUSR set to a steady bar. \x1b[!p puts every one of those private modes back to default in a single round-trip — without losing the scrollback the user might want to review. Contrast RIS (\x1bc, see ris-reset) which does the same reset *plus* clears the screen, wipes the scrollback, and on Linux console reinitialises the entire terminal state (font table, palette) — RIS is the bigger hammer when DECSTR isn't enough but is destructive to scrollback the user may still need.

The catch list matters when planning a recovery script. DECSTR does NOT clear the screen (use \x1b[2J\x1b[H separately if needed), does NOT exit the alt-screen (use \x1b[?1049l, see alt-screen), and on some xterm builds does NOT undo DECSET ?1000 / ?1006 mouse tracking, ?2004 bracketed paste, or ?1004 focus events — the xterm matrix has shifted across releases, and kitty / wezterm reset more private modes than xterm does. For a guaranteed full cleanup after a crashed TUI, the durable shell-prompt recipe is printf '\x1b[?1049l\x1b[?1000l\x1b[?1006l\x1b[?2004l\x1b[?1004l\x1b[!p\x1b[?25h' — DECRST the leakage-prone private modes one by one, then DECSTR for everything else, then explicitly show the cursor. Some shells expose a built-in for this (reset-tty in fish, stty sane covers the kernel side but not the terminal-emitter side). Related: ris-reset (RIS \x1bc — hard reset, wipes scrollback), sgr-reset (SGR 0 — colour / attribute reset only, the lightest hammer), alt-screen (DECSET ?1049 — must be disabled separately from DECSTR).

Spec citation: xterm-ctlseqs (DECSTR, CSI ! p)

Examples

bash
printf '\033[!p'   # soft reset; scrollback preserved
python
import sys; sys.stdout.write('\x1b[!p')
go
fmt.Print("\x1b[!p")
javascript
process.stdout.write('\x1b[!p')
c
printf("\x1b[!p");

Frequently asked

Short answers to the questions developers actually search for this sequence.

What's the difference between DECSTR (\x1b[!p) and RIS (\x1bc)?
DECSTR is the soft reset — clears SGR state, cursor save slot, DEC private modes, scrolling region, origin mode, character sets back to defaults, but leaves the screen contents and scrollback intact. RIS is the hard reset — DECSTR everything plus clears the screen, resets tab stops, and on most terminals resets the palette. Use DECSTR to undo a TUI's mode changes without losing the user's history; use RIS only when you want a full power-on simulation.

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
yes
GNU screen
yes

Related sequences

In the family cookbook

ESC cookbook · 1. Hard reset vs. soft reset — `\x1bc` (RIS) and `\x1b[!p` (DECSTR)