Skip to content

Width and wrapping

By the end of this chapter you know where Glow's 80 comes from, how to change it, and what wrapping means for line numbers and long lines.

80, whatever your terminal says

Glow wraps its pages to 80 columns by default, and — this is the part that surprises — it does not ask your terminal how wide it is. The lab rendered the same document under pretend terminals 30, 50 and 120 columns wide; the longest rendered line measured 78 (80 minus the two-column margin) every time (transcript glow-lab/transcripts/t05-width.txt). A wide terminal gets an 80-column page with empty space beside it; a narrow one gets the same page, and lines its screen must wrap or clip all over again. There is one exception: the built-in pager (chapter 11) renders at the window's actual width. The printed page never does.

Changing it: -w

glow -w 40 file.md    → longest line 38, more and shorter lines
glow -w 0  file.md    → no wrapping at all

-w 0 deserves a warning. Unwrapped, a paragraph is one line however long it runs — the lab's test paragraph came out as a single 385-character line. Terminals will soft-wrap it for display, but anything downstream (another program, a file) receives the long line as-is. The width can also be set in the configuration file, where the lab verified it is honoured both on a terminal and in a pipe (chapter 12) — width, unlike style, is never ignored in a pipe.

Rendered lines are not source lines: wrapping cuts paragraphs where the width demands, tables take the width they need, and one source line can become several rendered ones. Keep that in mind for chapter 11's line numbers, which count the rendered lines.

The -n flag that changed nothing

-n (in full, --preserve-new-lines) is documented as preserving new lines when rendering — relevant because, as chapter 5 noted, Glow keeps single line breaks inside a paragraph as breaks on the page, where a web renderer would fold them into spaces. The lab tested the flag on two specimens built for the purpose — single breaks, runs of blank lines (runs of blank lines collapse to one either way) — and again at width 40. Every comparison came out byte-identical with the flag off (transcript glow-lab/transcripts/t10-newlines.txt).

This guide does not conclude the flag is broken; it concludes that on every specimen the lab tried, including the ones built to provoke it, it made no measurable difference, and the default behaviour already keeps the breaks. If a future version changes that, this paragraph is the one to re-test first. It is recorded here at this length because "we tried, and nothing happened, here is the evidence" is a result too.

Check: render a document in a wide terminal and measure the longest line (glow file.md | awk '{if(length($0)>m) m=length($0)}END{print m}' — expect 78). Then -w 40 and expect 38. If both land, the width is yours.