Skip to content
Latchkey

fmt: Reflow and Wrap Text in CI

fmt -w N reflows paragraphs so lines are at most N characters wide, preserving blank-line breaks.

Generated release notes and commit bodies read better wrapped to a fixed width. fmt reflows text without mangling paragraph structure.

What it does

fmt joins and re-splits lines within a paragraph so no line exceeds the target width (default around 75, set with -w). Blank lines separate paragraphs and are preserved. -s splits long lines but never joins short ones; -u normalizes spacing. Part of coreutils.

Common usage

Terminal
# wrap to 72 columns for a commit message body
fmt -w 72 body.txt
# split only, do not join short lines
fmt -s -w 80 notes.md
# reflow generated changelog text
git log --format='%b' v1.0..HEAD | fmt -w 72
# uniform spacing (one space between words)
fmt -u paragraph.txt

Options

FlagWhat it does
-w <n>Maximum line width (default ~75)
-sSplit long lines only; never join short ones
-uUniform spacing: one space between words, two after sentences
-p <prefix>Only reformat lines beginning with prefix
-cCrown margin: preserve indentation of first two lines

In CI

When auto-generating a changelog or PR body, pipe through fmt -w 72 so the text wraps cleanly in git and GitHub. Use -s for Markdown to avoid joining separate bullet lines into one paragraph, since fmt treats non-blank adjacent lines as the same paragraph.

Common errors in CI

fmt joining lines you meant to keep separate (bullets, code) is the usual complaint: it treats adjacent non-blank lines as one paragraph. Use -s to split-only, or separate blocks with blank lines. "fmt: invalid width" means a non-numeric -w. On Alpine, install coreutils; BusyBox omits fmt.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →