Skip to main content
ansicode

TBC — Tab Clear (CSI g)

Clear one or all tab stops, changing where HT and CBT land.

Byte forms

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

\\x1b[\x1b[g (clear current) \x1b[3g (clear all)
\\033[\033[g / \033[3g
\\e[\e[g / \e[3g
ESC [ESC [ Ps g
hex1b 5b <Ps> 67

Description

ECMA-48 §8.3.154 — Tabulation Clear (TBC). Final byte g (0x67). The parameter controls scope: 0 (default, also when omitted) clears the tab stop *at the current column* only; 3 clears *all* tab stops in the entire terminal. Byte sequences \x1b[g (clear-here) and \x1b[3g (clear-all). Pair with HTS (\x1bH, see esc-hts) which sets a tab stop at the current column — TBC is the matching "clear" half. Default tab stops sit every 8 columns (cols 9, 17, 25, …); every freshly-opened terminal starts with that grid, and \x1b[3g is the primitive that wipes the slate clean before HTS lays down a custom layout that matches your forms / tables / column-aligned output.

Portability — universal across xterm, iTerm2, kitty, alacritty, wezterm, gnome-terminal, Konsole, Ghostty, Linux console, Windows Terminal, ConPTY 1809+. Pre-ConPTY cmd.exe ignored TBC. The most common authoring surprise: once you've issued \x1b[3g, HT (\t, 0x09) does *nothing* — there are no tab stops to advance to, so the cursor stays put and tools that emit \t for layout (column, pr, expand, Makefile recipe output, many heredoc-formatted strings) silently produce broken / left-aligned output until new stops are set. The defensive pattern is to always pair \x1b[3g with a sequence of HTS emissions before returning control to the user; never leave the terminal in a "tab stops wiped, none set" state, which is a particularly nasty form of state-leak after a crashed TUI. terminfo capability tbc exists but is rarely populated by terminal entries; programs typically emit the bytes directly.

The wipe is persistent across normal screen operations — SGR 0, screen clears (\x1b[2J), Ctrl+L form-feed (\x0c), and even a fresh prompt do NOT restore the default 8-column grid. Only DECSTR (\x1b[!p, see decstr-soft-reset), RIS (\x1bc, see ris-reset), or another TBC + HTS sequence will undo it. tmux normalises tab stops to the default 8-column grid on its inner pseudo-terminal, so TBC issued inside a tmux pane is intercepted at the multiplexer boundary rather than forwarded to the outer terminal — same behaviour as HTS, and the same pair of caveats applies (tmux-aware code should re-emit the desired tab layout when reattaching to a session). GNU screen behaves the same way. Related: esc-hts (HTS — the matching "set tab stop here" half), csi-cbt (CBT — \x1b[<N>Z retreats backward by N stops, the symmetric counterpart to CHT), c0-controls (the C0 table including HT \x09 — the literal tab character whose behaviour TBC controls).

Spec citation: ECMA-48 §8.3.154 (TBC)

Parameters

0clear tab stop at current column
3clear ALL tab stops

Examples

bash
printf '\033[3g'      # clear all tab stops\nprintf '\033H'        # set a tab stop here (HTS, ESC H)
python
import sys; sys.stdout.write('\x1b[3g')
go
fmt.Print("\x1b[3g")
javascript
process.stdout.write('\x1b[3g')
c
printf("\x1b[3g");

Used in

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

  • vim / neovim `:set tabstop=N`Changing `tabstop` mid-buffer triggers a `\x1b[3g` (TBC mode 3 — clear all tab stops) followed by HTS (`\x1bH`) at each new stop column — visible in `:redir @a` capture during `:set tabstop=4` then `:set tabstop=8`
  • GNU coreutils `expand` / `unexpand`Implementations that write to a real TTY (vs piped output) emit TBC to reset stops before the conversion to keep `expand --tabs=4 file` deterministic across terminal default-tab-stops (some VTs default to every 8, others every 10)
  • ed(1) `T` command (set tab)BSD ed and FreeBSD ed implement the historic `T` command by emitting `\x1b[g` (TBC mode 0 — clear stop at current column) followed by repositioning — preserved for POSIX.1-2024 compatibility, rarely invoked in modern shells
  • terminfo `tbc` capability (clear_all_tabs)The `tbc` cap is hardcoded as `\E[3g` in `xterm-256color`, `linux`, `screen-256color` and ~280 other terminfo entries — `tput tbc` resolves to the same bytes, used by initscripts and `tset` to normalise tab stops at login
  • Emacs `tab-width` buffer-local recalcWhen a buffer-local `tab-width` changes via `set-variable RET tab-width RET`, the redisplay engine emits TBC + HTS pairs to align the new stops — the same pattern is used by `M-x untabify` after region conversion to ensure further tab presses align

Frequently asked

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

What's the difference between \x1b[g and \x1b[3g?
\x1b[g (parameter omitted, same as \x1b[0g) clears the tab stop *at the current cursor column only* — every other stop in the terminal stays put. \x1b[3g clears *all* tab stops site-wide. There is no middle ground: ECMA-48 §8.3.154 defines exactly two scopes via parameter 0 and 3; other values are reserved and most terminals ignore them. Practical impact: \x1b[g after CUP-positioning at column 9 deletes only the column-9 stop, leaving 17 / 25 / 33 / ... intact and HT still advancing as expected. \x1b[3g wipes the slate, after which HT (\t) becomes inert until you lay new stops via HTS (\x1bH, see esc-hts).
How do I restore the default 8-column tab grid after \x1b[3g?
Three options, in increasing blast-radius. (1) Re-emit HTS at each desired column: CUP to column 9, \x1bH; CUP to column 17, \x1bH; repeat to the terminal width. This is the only surgical option — leaves all other DEC state untouched. (2) DECSTR soft reset (\x1b[!p, see decstr-soft-reset) — restores tab stops along with cursor visibility, origin mode, autowrap, and most DEC private modes; safe between TUI sessions but resets more than you may want. (3) RIS hard reset (\x1bc, see ris-reset) — also clears scrollback and SGR state; usually too aggressive for inside an application. Note that screen clears (\x1b[2J), form-feed (\x0c), and SGR 0 do NOT restore tab stops — this is the most common authoring trap with TBC.

Terminal support

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

Related sequences

In the family cookbook

ESC cookbook · 2. Tab stops — `\x1bH` (HTS) sets, `\x1b[g` (TBC) clears