brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: fmt -w rewraps a paragraph so all lines get the same length

Linux
~/tips/tip-linux-fmt-reflow-paragraphs

fmt -w 72 notes.txt

Reflow ragged lines in notes, commit messages or a README to one width.

After a few edits, a plain text paragraph has a mix of short and long lines. fmt joins them and wraps them again at the width you choose.

fmt -w 72 notes.txt

Unlike fold, which only breaks lines that are too long, fmt also pulls short lines together, so the paragraph ends up even. Blank lines stay where they are, so separate paragraphs stay separate. Indentation is kept too.

For a quick feel of what it does:

echo 'one two three four five six seven eight nine ten eleven' | fmt -w 20

That gives four lines of three or two words each, none longer than twenty characters.

I like it inside an editor that can pipe a selection through a command. In Vim, :'<,'>!fmt -w 72 rewraps the lines you selected, which is handy for commit messages and email.

-u also evens out the spacing, with one space between words and two after a sentence. If you only want long lines broken and short ones left alone, use -s.

Keep it away from code, lists and tables. fmt does not know Markdown, so bullet points that follow each other can end up merged into one line. Run it on prose only, and write the result to a new file first so you can compare.

Further reading: GNU coreutils: fmt invocation

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link