Skip to main content
ansicode

DECSET 1049 — Alternate screen buffer

Switch to a separate screen buffer (like vim/less do on launch).

Byte forms

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

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

Description

DEC private mode 1049 is the canonical 'enter full-screen app' sequence. On enter (`h`), the terminal saves the cursor, switches to a fresh screen buffer (no scrollback), and clears it. On leave (`l`), the original buffer and cursor are restored — this is what lets you `q` out of `vim`/`less` and find your shell prompt exactly where you left it. Older modes 47 and 1047 do almost the same thing but without the cursor save/restore and clear behaviors.

Spec citation: xterm-ctlseqs (Private modes)

Examples

bash
printf '\033[?1049h'; sleep 2; printf '\033[?1049l'
python
import sys, time\nsys.stdout.write('\x1b[?1049h'); sys.stdout.flush(); time.sleep(2); sys.stdout.write('\x1b[?1049l')
go
fmt.Print("\x1b[?1049h"); time.Sleep(2*time.Second); fmt.Print("\x1b[?1049l")
javascript
process.stdout.write('\x1b[?1049h'); setTimeout(() => process.stdout.write('\x1b[?1049l'), 2000)
c
printf("\x1b[?1049h"); sleep(2); printf("\x1b[?1049l");

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

DEC cookbook · 1. The `?` prefix — DECSET vs SM