Skip to main content
ansicode

DECSLRM — Set left and right margins (CSI Pl ; Pr s)

Constrain horizontal cursor movement + scrolling to columns Pl…Pr — the horizontal counterpart of DECSTBM.

Byte forms

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

\\x1b[\x1b[<Pl>;<Pr>s
\\033[\033[1;80s
\\e[\e[1;80s
ESC [ESC [ Pl ; Pr s
hex1b 5b ... 73

Description

Set Left and Right Margins. Defines a vertical strip — columns `Pl` (leftmost) through `Pr` (rightmost), 1-based, inclusive — within which cursor movement and scrolling are confined. Requires DECLRMM (left-right margin mode, `\x1b[?69h`) to be enabled first; without DECLRMM the sequence is silently ignored, and the final byte `s` instead means SCO save-cursor (this is the parse ambiguity that bites: `\x1b[s` with no params = save cursor, `\x1b[<Pl>;<Pr>s` with 2 params = DECSLRM if DECLRMM=on). Once active, SL/SR scrolling stays inside the strip, CUF/CUB clamp at the boundaries, and writes that hit the right margin wrap to the next row's left margin (instead of column 1). Paired with DECSTBM (`\x1b[<Pt>;<Pb>r`) the two margins define a rectangular scrolling region — the foundation for split-pane editors like vim's `:vsplit` rendering its left half independently of the right. Defaults if omitted: `Pl=1`, `Pr=` last column. Setting `Pl≥Pr` resets to the full screen width.

Spec citation: DEC STD 070 (DECSLRM) / DEC VT510 RM

Parameters

PlLeftmost column (1-based, inclusive). Default 1.
PrRightmost column (1-based, inclusive). Default = screen width.

Examples

bash
printf '\033[?69h'        # enable DECLRMM first\nprintf '\033[10;30s'      # constrain cols 10..30\n# now scrolling + cursor moves stay within that strip
python
import sys\nsys.stdout.write('\x1b[?69h')          # enable DECLRMM\nsys.stdout.write('\x1b[1;40s')          # left margin 1, right 40
go
fmt.Print("\x1b[?69h\x1b[1;40s")    // enable + set strip
javascript
process.stdout.write('\x1b[?69h\x1b[1;40s')
c
printf("\x1b[?69h\x1b[1;40s");    /* enable DECLRMM + constrain to cols 1..40 */

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
no
iTerm2
partial
Windows Terminal
no
cmd.exe / ConPTY
no
kitty
yes
alacritty
no
WezTerm
yes
Ghostty
partial
GNOME Terminal
no
Konsole
yes
tmux
no
GNU screen
no

Related sequences

In the family cookbook

CSI cookbook · 5. Margins & scroll region — DECSTBM `r` and DECSLRM `s`