REP — Repeat Preceding Character (CSI Pn b)
Repeat the most-recently-emitted printing character N times — a bandwidth-saver for runs of identical glyphs.
Byte forms
Every common string-literal form so you can paste-and-search either direction.
\x1b[Pnb\033[Pnb\e[PnbESC [ Pn b1b 5b <Pn> 62Description
Repeat Preceding Character. Final byte b (0x62) prints the most-recent graphic character (the one that updated the terminal's display, NOT a control code or whitespace) Pn more times (default 1). If the previous emitted byte was a control or none-yet, REP is a no-op. Useful in narrow SSH links: drawing a horizontal rule of 80 ─ chars costs 80 multi-byte UTF-8 bytes (160-240 bytes) versus ─\x1b[79b (5 bytes + 4 control bytes = 9 bytes). Supported by xterm (since X11R5), kitty, wezterm, ghostty, alacritty, mintty, foot; Windows Terminal added support in 1.18+; iTerm2 doesn't support it. Apps that emit decorative box-drawing or progress-bar fills can preflight via XTGETTCAP for the rep cap before using it. Terminfo cap: rep.
Spec citation: ECMA-48 §8.3.103 (REP)
Examples
# 80-char horizontal rule with minimal bytes:\nprintf '\xe2\x94\x80\033[79b\n'import sys; sys.stdout.write('-\x1b[79b\n') # 80 dashesfmt.Print("-\x1b[79b\n")process.stdout.write('-\x1b[79b\n')printf("-\x1b[79b\n");Used in
Real-world tools that emit this sequence — anchors the bytes to commands you've already used.
- ANSI horizontal-rule emitters (CLI banners)Bash one-liners like `printf '\xe2\x94\x80\033[$((COLUMNS-1))b\n'` draw a full-width box-drawing rule with O(1) bytes regardless of terminal width — used by `gh pr view --comments`, `glab issue view`, and most modern CLIs over `seq` + `printf` loops
- neovim screen redraw (when `set lazyredraw`)neovim batches buffer updates and emits REP for runs of identical glyphs (whitespace fill, undrawn-pane stubs) during the redraw flush — visible in `:set verbose=20` traces as `<Esc>[ Nb` clusters
- fastfetch / neofetch ASCII art rendererDistribution logo ASCII renders use REP to compress runs of the same colour-block character (`█`) — a 60×40 logo shrinks from ~12 KB of UTF-8 to ~3 KB on terminals advertising the `rep` cap, with literal fallback otherwise
- less progress bar / file-size column paddingless ≥ 600 uses REP to pad the bottom-line `:` prompt with spaces when the file size column is narrow — `\033[<N>b` keeps the screen redraw under 50 bytes per status update on a 200-column terminal
- Windows Terminal 1.18+ test pattern generatorMicrosoft's `wt`-launched test pattern UI (Settings → Render → Test pattern) emits REP-heavy gradients to verify the renderer's batch handling — a regression in 1.21 that broke REP on truecolor cells was caught by this fixture
Frequently asked
Short answers to the questions developers actually search for this sequence.
- Does REP (
\x1b[Pn b) repeat the most recent control sequence, the most recent byte, or the most recent printing character? - Strictly the most recent *graphic character* — the one that updated the terminal's display. Control codes (CR, LF, BS), SGR sequences, cursor moves, and whitespace are skipped; if no graphic character has been emitted yet, REP is a no-op.
printf '─\033[79b'prints 80─;printf '\033[31m\033[79b'(SGR then REP, no graphic character between) prints nothing. The spec language is ECMA-48 §8.3.103: "REP causes the preceding graphic character to be repeated". - Why isn't REP supported on macOS Terminal / iTerm2?
- Apple's Terminal.app and iTerm2 are historic VT100-family emulators built before REP was widely deployed — REP was an xterm extension (since X11R5) that VT100 didn't define. Apple's parser routes the final byte
bto a no-op rather than the REP handler, so\x1b[5bprints nothing instead of repeating. The portable pattern: probeXTGETTCAP rep(\x1bP+q726570\x1b\\) at startup, fall back to a literal loopprintf '─' x 80if the cap is missing. Modern terminals (kitty, wezterm, Ghostty, foot, alacritty, mintty, Windows Terminal ≥ 1.18) implement it; Linux console implements it too (via the in-kernelconsole_codes(4)VT subset).
Terminal support
- xterm
- yes
- Linux console (fbcon)
- yes
- macOS Terminal.app
- no
- iTerm2
- no
- Windows Terminal
- yes
- cmd.exe / ConPTY
- no
- kitty
- yes
- alacritty
- yes
- WezTerm
- yes
- Ghostty
- yes
- GNOME Terminal
- partial
- Konsole
- yes
- tmux
- yes
- GNU screen
- yes
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | yes | no | no | yes | no | yes | yes | yes | yes | partial | yes | yes | yes |