SCP/RCP
SCP (Save Cursor Position) and RCP (Restore Cursor Position) are CSI sequences originating from ANSI.SYS that save and restore the cursor position.
Syntax
CSI s SCP — Save Cursor Position
CSI u RCP — Restore Cursor Position
SCP = 0x1b, "[", "s" ; RCP = 0x1b, "[", "u" ;
Description
- SCP (
CSI s) — Saves the current cursor position (row and column). - RCP (
CSI u) — Restores the cursor to the position previously saved by SCP.
These sequences originated in MS-DOS ANSI.SYS and save only the cursor position — not character attributes, character sets, or other terminal state. This is in contrast to DECSC/DECRC (ESC 7 / ESC 8), which saves a more complete snapshot of terminal state.
Conflict with DECSLRM
CSI s is also used for DECSLRM (Set Left and Right Margins) when left/right margin mode (DECLRMM, mode 69) is enabled. When DECLRMM is set, CSI s with parameters sets the left and right margins rather than saving the cursor. The parameterless form CSI s (no arguments) can be ambiguous in this context, so applications needing both left/right margins and cursor save/restore should use DECSC/DECRC instead.
Because DECSC/DECRC saves more state and avoids the DECSLRM conflict, it is generally preferred over SCP/RCP. SCP/RCP remains widely supported for compatibility with ANSI.SYS-era software.
Examples
printf '\e[s' # Save cursor position
printf '\e[10;20H' # Move cursor elsewhere
printf 'Hello'
printf '\e[u' # Restore cursor to saved position
Specifications
| Specification | Section |
|---|---|
| XTerm ctlseqs | — |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ✓ | 0.1.0 | Implemented via save_cursor_position/restore_cursor_position |
| Bobcat | ✓ | 0.9.0 | Supported via TerminalCtrl library |
| contour | ✓ | v0.1.0 | ANSI.SYS style via SCOSC (CSI s) and ANSISYSSC (CSI u) |
| foot | ✓ | Yes | SCP (s) at csi.c:1250-1252, RCP (u) at csi.c:1254-1256 |
| Ghostty | ✓ | v1.0.0 | Both ANSI.SYS (CSI s/u) and DEC (ESC 7/8) variants |
| iTerm2 | ✓ | Yes | ANSICSI_SCP/RCP and VT100CSI_DECSC/DECRC tokens handled via saveCursor/restoreCursor |
| Kitty | ✓ | Yes | SCP/RCP (CSI s/u) ANSI.SYS style implemented in vt-parser.c:1258-1305 |
| Konsole | ✓ | Yes | ANSI.SYS style CSI s/u save/restore cursor at src/Vt102Emulation.cpp:2031-2032 |
| mintty | ✓ | Yes | SCOSC/SCORC (CSI s/u) at lines 3401-3404, uses save_cursor/restore_cursor functions |
| mlterm | ✓ | rel-2_9_0 | ANSI.SYS style (CSI s/u) at vt_parser.c:5879-5890,5972-5975; Also supports DEC style (ESC 7/8) |
| PuTTY | ✓ | 0.45 | |
| Rio | ✓ | v0.0.3 | |
| rxvt-unicode | ✓ | 1.2 | Uses CSI s/u (ANSI.SYS), not DEC DECSC/DECRC |
| st | ✓ | 0.1 | ANSI.SYS variant using CSI s/u, not DEC DECSC/DECRC (ESC 7/8) |
| terminology | ✓ | v0.1.0 | Implemented as CSI s/u (SCOSC/SCORC) |
| VT100 | ✗ | No | |
| VTE | ✓ | Yes | Implemented as SCOSC/SCORC for CSI s/u compatibility (not the ECMA-48 SCP) |
| WezTerm | ✓ | Yes | SCP/RCP (ANSI.SYS style) implemented as Cursor::SaveCursor and Cursor::RestoreCursor, with ambiguity resolution for DECSLRM |
| Windows Terminal | ✓ | Yes | ANSI.SYS cursor restore (CSI u) implemented at OutputStateMachineEngine.cpp:546 as ANSISYSRC_CursorRestore. Note: CSI s can be ANSISYSSC or DECSLRM depending on DECLRMM mode. |
| xterm | ✓ | xterm-406 | Only available when DECLRMM disabled |
| xterm.js | ✓ | 2.3.0 | CSI s/u (ANSI.SYS style) and ESC 7/8 (DEC style) both supported |
| Multiplexers | |||
| cy | ✓ | v0.1.0 | |
| GNU Screen | ✓ | v.4.2.0 | |
| tmux | ✓ | 1.6 | SCP (CSI s) and RCP (CSI u) for ANSI.SYS-style cursor save/restore |
| tuios | ~ | v0.0.15 | CSI s (save) supported, but CSI u (restore) not implemented. Use ESC 7/ESC 8 instead. |
| Zellij | ✓ | v0.10.0 | ANSI.SYS variant (CSI s/u), not DEC variant (ESC 7/8) |
See also
- DECSC/DECRC — Save/Restore Cursor — DEC version that saves more state
- DECSLRM — Set Left and Right Margins — Shares the
CSI ssequence