Skip to main content

DECSC/DECRC

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Standard

DECSC (Save Cursor) and DECRC (Restore Cursor) are DEC VT100 escape sequences that save and restore the cursor position along with associated terminal state.

Syntax​

ESC 7         DECSC — Save cursor
ESC 8 DECRC — Restore cursor
Formal syntax
DECSC = 0x1b, "7" ;
DECRC = 0x1b, "8" ;

Description​

DECSC — Save cursor (ESC 7)​

Per the VT510 manual, DECSC saves the following state:

  • Cursor position (row and column)
  • Character attributes (set by SGR)
  • Character sets designated in GL and GR (G0, G1, G2, G3)
  • Autowrap mode (DECAWM) state
  • Origin mode (DECOM) state
  • Selective erase attribute
  • Any pending single-shift (SS2/SS3) state

DECRC — Restore cursor (ESC 8)​

DECRC restores the state previously saved by DECSC. If DECSC has not been issued since the terminal was powered on or reset, DECRC applies these defaults:

  • Cursor moves to the home position (row 1, column 1)
  • Origin mode is reset
  • All character attributes are turned off
  • ASCII is mapped into GL, DEC Supplemental Graphic into GR

Save buffer​

The terminal maintains a single save buffer. Calling DECSC again overwrites the previously saved state. The main screen and alternate screen each have their own independent save buffer.

note

The ANSI equivalent is SCP/RCP (CSI s / CSI u), but DECSC/DECRC saves more state. Many applications prefer DECSC/DECRC for this reason.

Examples​

printf '\e7'          # Save cursor position and state
printf '\e[10;20H' # Move cursor elsewhere
printf 'Hello' # Write some text
printf '\e8' # Restore cursor to saved position

Specifications​

SpecificationSection
VT510 Reference—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✓YesESC 7/8 listed as IMPLEMENTED in docs/escape_support.md; handlers save_cursor_position() at term/mod.rs:1619 and restore_cursor_position() at term/mod.rs:1626
Bobcat✓0.9.0Save/restore cursor, TerminalCtrl has high DEC VT compatibility
contour✓v0.1.0ESC 7 (DECSC) and ESC 8 (DECRC) save/restore cursor state
foot✓YesImplemented in vt.c:472-477 as ESC 7/8
Ghostty✓v1.0.0ESC 7 and ESC 8 handled in stream.zig:2134-2151
iTerm2✓Yes
Kitty✓Yes
Konsole✓Yes
mintty✓YesDECSC (ESC 7) at src/termout.c:1952-1953, DECRC (ESC 8) at src/termout.c:1954-1955
mlterm✓rel-0_2_1
PuTTY✓0.45
Rio✓v0.0.28
rxvt-unicode✓rxvt-unicode-1.2
st✓0.4
terminology✓v0.1.0
VT100✓Yes
VTE✓Yes
WezTerm✓YesHandled in performer.rs:632-633 via EscCode::DecSaveCursorPosition (ESC 7) and DecRestoreCursorPosition (ESC 8)
Windows Terminal✓YesESC 7 calls CursorSaveState(), ESC 8 calls CursorRestoreState() in OutputStateMachineEngine.cpp:202-206
xterm✓YesImplemented in charproc.c:4902-4920 via CursorSave/CursorRestore
xterm.js✓3.5.0
Multiplexers
cy✓v0.1.0
GNU Screen✓v.4.2.0DECSC (ESC 7) and DECRC (ESC 8) at src/ansi.c:727-731
tmux✓1.3Save/restore cursor via input_save_state/input_restore_state
tuios✓v0.0.15
Zellij✓v0.7.0

See also​