Skip to main content
ansicode

DECSET ?1047 — Alt screen without cursor save

Switch to / from the alt screen WITHOUT saving the cursor — the bare-bones precursor to ?1049.

Byte forms

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

\\x1b[\x1b[?1047h (enter alt) \x1b[?1047l (leave alt)
\\033[\033[?1047h / \033[?1047l
\\e[\e[?1047h / \e[?1047l
ESC [ESC [ ? 1 0 4 7 h / l
hex1b 5b 3f 31 30 34 37 68 / 6c

Description

Three private modes exist for alt-screen handling — ?47, ?1047, and ?1049. ?1047 switches to/from the alt screen but does NOT save or restore the cursor; ?1048 ONLY saves/restores the cursor (no screen switch); ?1049 is the modern composite: save cursor + enter alt + clear, and on exit restore alt → main + restore cursor. Apps that genuinely don't care about cursor position (animation toys, simple status-bar utilities) can save bytes with ?1047. Apps that need both (vim, less, tmux, htop) emit ?1049 — never the lower-level pair. Note: when leaving alt-screen via ?1047l xterm also clears the main screen before flipping, which can surprise applications expecting a non-destructive flip.

Spec citation: xterm-ctlseqs (Private mode 1047)

Examples

bash
printf '\033[?1047h'   # switch to alt; cursor position NOT saved\nprintf '\033[?1047l'   # back to main; main screen is cleared first
python
import sys; sys.stdout.write('\x1b[?1047h')
go
fmt.Print("\x1b[?1047h")
javascript
process.stdout.write('\x1b[?1047h')
c
printf("\x1b[?1047h");

Frequently asked

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

When should I use ?1047 instead of ?1049?
Almost never — ?1049 is what every modern TUI should use. ?1049 is *atomic*: it saves the cursor (DECSC), switches to the alt buffer, and clears it in one operation; ?1049l reverses all three. ?1047 only does the buffer switch — no cursor save, no clear — so you have to emit \x1b7 (DECSC) and \x1b[2J (or \x1b[3J for scrollback) yourself, in the right order, with matching cleanup on exit. The only reason to pick ?1047 today is targeting a legacy terminal whose ?1049 implementation is broken (none in the modern matrix qualifies) — and even then, ?1047 plus explicit DECSC / clear gets you ?1049 behaviour at the cost of more bytes and more failure surface.
Does ?1047 preserve the scrollback when entering / exiting?
Yes — ?1047 leaves the *primary* buffer's scrollback intact across the round-trip. The alt buffer itself has no scrollback (it's a fixed-size screen-shaped buffer with no history). When you exit ?1047l, the primary buffer's pre-?1047h scrollback is back exactly as it was; the alt buffer's content is discarded. If you want a clean alt canvas, emit \x1b[3J (ED 3 — clear scrollback) before ?1047h on the alt side, or just use ?1049 which handles the clear in the same atomic operation.

Terminal support

xterm
yes
Linux console (fbcon)
no
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

DEC cookbook · 2. Alt-screen — `\x1b[?1049h` / `l`