Skip to main content
ansicode

DECCRA / DECFRA / DECERA / DECSERA — Copy / Fill / Erase / Selective-erase rectangular area

The four content-side rectangle ops missing from the DEC rect family — copy a block, fill it with a glyph, erase to space, or erase only non-protected cells. Pairs with DECCARA / DECRARA (attribute-side) and DECSACE (block-vs-stream toggle).

Byte forms

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

\\x1b[\x1b[<Pts>;<Pls>;<Pbs>;<Prs>;<Pps>;<Ptd>;<Pld>;<Ppd>$v DECCRA\n\x1b[<Pch>;<Pt>;<Pl>;<Pb>;<Pr>$x DECFRA\n\x1b[<Pt>;<Pl>;<Pb>;<Pr>$z DECERA\n\x1b[<Pt>;<Pl>;<Pb>;<Pr>${ DECSERA
\\033[\033[1;1;10;40;1;15;5;1$v / \033[42;3;5;10;40$x / \033[3;5;10;40$z / \033[3;5;10;40${
\\e[\e[1;1;10;40;1;15;5;1$v / \e[42;3;5;10;40$x / \e[3;5;10;40$z / \e[3;5;10;40${
ESC [ESC [ Pts;Pls;Pbs;Prs;Pps;Ptd;Pld;Ppd $ v / $ x / $ z / $ {
hex1b 5b … 24 76 / 1b 5b … 24 78 / 1b 5b … 24 7a / 1b 5b … 24 7b

Description

Four DEC ops sharing the $ intermediate that *do* touch character data inside a rectangle — DECCARA / DECRARA only re-attribute. Each rectangle uses 1-indexed inclusive coordinates and obeys the current scroll region + origin mode. Block-vs-stream interpretation of the rectangle is selected by DECSACE (\x1b[Ps*x).

DECCRA — *Copy Rectangular Area*, $v. Eight parameters: source rect (Pts;Pls;Pbs;Prs;Pps), then destination top-left (Ptd;Pld;Ppd). Pps/Ppd are page numbers (1 on every modern single-page emulator — DEC VT525 had multi-page memory). The op is a *cell-for-cell* copy: characters + their per-cell attributes move together; cells outside the destination's visible area are clipped, not wrapped. Overlapping source / destination is handled correctly (terminals typically copy through an internal scratch buffer so a top-to-bottom shift is safe).

DECFRA — *Fill Rectangular Area*, $x. Five parameters: the glyph code (Pch, a 7-bit decimal code 32–126; or a 16-bit code on UTF-8-aware emulators), then Pt;Pl;Pb;Pr rectangle. Every cell is overwritten with the glyph, gaining the *current* SGR pen as its attributes. Common uses: clear an inset to a single character (DECFRA with Pch=32 is the per-rect equivalent of clear), draw a solid frame with (U+2588) on a UTF-8 emulator, or pre-fill scratch panes.

DECERA — *Erase Rectangular Area*, $z. Four parameters: the rectangle. Equivalent to DECFRA with Pch=32 (space) *and* the cell attributes reset to default — so it leaves a *fully cleared* rect, not a 'spaces with current pen'. The reset includes the SGR layer, foreground/background colour, and the selective-erase protection bit.

DECSERA — *Selective Erase Rectangular Area*, ${. Four parameters: the rectangle. Like DECERA *but* respects the DECSCA-protected bit: cells that were marked protected via \x1b[1"q survive. The other cells clear to space + default attrs. This is the rect-form of decsed-decsel (selective ED / EL) and the only way to clear a form template without wiping the labels.

Stream mode (DECSACE). With \x1b[2*x in effect, Pt;Pl and Pb;Pr are interpreted as stream-start and stream-end positions instead of rectangle corners — the affected cells are every cell between the two positions following normal text-flow (line-wrap aware). Stream-mode is only wired through DECCARA / DECRARA on every shipping emulator; the four content ops above keep block semantics regardless of DECSACE. This is a *DEC-vs-VT510* deviation in xterm and family — verify with DECRQM ?92 if you need to depend on it.

Coverage: xterm = full all four. Konsole = full. WezTerm + Ghostty = full (DECFRA + DECERA), DECCRA + DECSERA partial. gnome-terminal + mlterm = full. iTerm2 = partial (no DECSERA, others honour current SGR pen rather than reset). Kitty = DECERA + DECFRA full, DECCRA + DECSERA no-op. Alacritty + Windows Terminal + cmd / ConPTY + Linux console + macOS Terminal = no-op (silently consumed). Feature-probe with xtversion plus a DECRQSS round-trip on $z before relying.

Spec citation: DEC VT510 RM (DECCRA / DECFRA / DECERA / DECSERA) / xterm-ctlseqs (CSI ... $ v / x / z / {)

Parameters

Pts;Pls;Pbs;Prs;Pps (DECCRA)Source rectangle top / left / bottom / right / page (1-indexed, inclusive).
Ptd;Pld;Ppd (DECCRA)Destination top-left row / col / page.
Pch (DECFRA)Glyph code to fill with — 32–126 (7-bit ASCII) on classic DEC; many modern emulators accept up to U+FFFF.
Pt;Pl;Pb;Pr (DECFRA / DECERA / DECSERA)Rectangle top row / left col / bottom row / right col, 1-indexed inclusive.

Examples

bash
# Copy rows 1-5 cols 1-40 to rows 20-24 cols 41-80.\nprintf '\\033[1;1;5;40;1;20;41;1$v'\n# Fill a status bar with U+2588 (decimal 9608) — needs UTF-8 emulator.\nprintf '\\033[9608;24;1;24;80$x'\n# Erase rows 5-10 cols 5-75 (clear an inset region).\nprintf '\\033[5;5;10;75$z'
python
import sys\n# Form-field clear: keep DECSCA-protected labels, clear data cells.\nsys.stdout.write('\\x1b[3;10;20;70${')   # DECSERA\nsys.stdout.flush()
go
// Pre-fill a help pane with '·' (decimal 183) before drawing content.\nfmt.Print(\"\\x1b[183;1;1;24;80$x\")
javascript
// 'Reset the canvas inset' — DECERA wipes both glyph + attrs to default.\nprocess.stdout.write('\\x1b[2;2;23;79$z');
c
/* Duplicate a logo block from rows 1-6 cols 1-30 to a side panel. */\nprintf(\"\\x1b[1;1;6;30;1;1;51;1$v\");

Used in

Real-world tools that emit this sequence — anchors the bytes to commands you've already used.

  • vim visual-block `Ctrl-v` operationsBlock-visual yank / paste / change in vim on a DEC-rect-aware terminal (xterm with `--enable-rectangle-graphics`) uses DECCRA `\x1b[...$v` for the paste-to-other-rectangle phase instead of per-cell loops — `:set verbose=15` then `Ctrl-v` over a block and `P` shows the rect op in the verbose log
  • neovim virtual-block mode (`g Ctrl-v`)Neovim's virtual-block mode allows selecting past line ends; on xterm-compatible rect support the redraw uses DECFRA `\x1b[<sp>;<t>;<l>;<b>;<r>$x` to fill the virtual cells with spaces before painting — falls back to per-cell SGR loops on terminals without rect support (most VTE)
  • fbterm / Linux-console no-op fallbackLinux framebuffer console (fbcon) does not implement any DEC rect ops — sequences are silently dropped; applications must check `infocmp linux | grep rect` (returns nothing) and disable the rect-op code path. Same on Apple Terminal, gnome-terminal pre-3.40, konsole < 22.04
  • kitty selection-rectangle modeKitty's rectangular selection (`Alt+drag` or `kitty.conf: rectangle_select_modifiers ctrl+alt`) implements the visual primitive natively but does NOT emit DECCRA for clipboard — it shovels selection bytes through OSC 52 instead. The DEC rect ops on kitty are limited to DECCARA (attribute re-paint inside an area)
  • WezTerm column-selection toggleWezTerm's column-select (`Ctrl+Shift+drag` default, configurable via `keys` Lua) renders the highlight via local OpenGL primitives — it doesn't round-trip through DECCRA. The DEC rect ops are partially implemented in the parser for `\x1b[...$x` / `\x1b[...$z` (xterm compatibility) but not exposed to user-config

Frequently asked

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

What's a 'rectangular operation' in DEC VT terminology — DECCRA / DECFRA / DECERA / DECCARA / DECRARA?
A family of CSI sequences that act on a rectangular region of the screen rather than the cursor's row / column. The five core ops: DECCRA \x1b[<srcT>;<srcL>;<srcB>;<srcR>;<srcPage>;<dstT>;<dstL>;<dstPage>$v copies one rectangle to another, DECFRA \x1b[<ch>;<t>;<l>;<b>;<r>$x fills with a character, DECERA \x1b[<t>;<l>;<b>;<r>$z erases (resetting attributes), DECCARA \x1b[<t>;<l>;<b>;<r>;<attr>$r changes attributes in place, DECRARA \x1b[<t>;<l>;<b>;<r>;<attr>$t reverses attributes (XOR). Coordinates are 1-based and INCLUSIVE on both ends. Supported by xterm, mlterm, kitty (partial), and almost nothing else — VTE-based terminals (gnome-terminal, konsole) do not implement; Windows Terminal stub-supports DECCARA only. Use case is high-throughput TUI scrollers (vim block-paste, the old DEC VT420 forms editor); for portable code, fall back to per-cell CUP+SGR loops.
How do I detect rectangular-ops support before using DECCRA / DECFRA?
There is no dedicated capability bit. The canonical probe is XTVERSION \x1b[>q (see xtversion) — a \x1bP>|XTerm(...)\x1b\\ reply with a recent patch level or \x1bP>|kitty(...)\x1b\\ confirms support; anything else assume unsupported. A fallback heuristic is to attempt DECFRA on a tiny safe region (e.g. \x1b[32;1;1;1;1$x to fill cell (1,1) with space) and then query DSR \x1b[6n — if the cursor moved (it shouldn't) you're on a terminal that mis-parsed the sequence as something else. In practice, terminfo lacks a rect_* cap, so the only way is XTVERSION or hardcoding the support matrix. Safest pattern: ship a --no-rect-ops flag that disables the optimisation and falls back to per-cell loops.

Terminal support

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

Related sequences