Sam asked a good question after the fold
post from yesterday. What’s the difference between fold
and fmt
?
Here’s fold
on the top and fmt
on the bottom.
First, fmt
doesn’t want to break words. fold
will, given the opportunity, and actually has to be told to wrap at spaces.
fmt
will also correct some spacing issues. Tacking on the -u
option pulls extra spaces and fills two spaces after a period. (My secondary school typing teacher would be proud.)
Plus, fmt
also has some more sophisticated “margin” handling. You can tell fmt
to push to within X percent of the wrap limit — a “goal” — and then break a line. I’ve seen word processors with that kind of feature, usually for hyphenation.
And judging by the man page, fmt
tries to avoid breaking lines at the first word or before the last word, meaning it has some rudimentary widow and orphan control.
fmt
can also set special indentations, split but not refill lines and screen lines before applying formatting.
So I guess the answer is … fmt
seems a bit more attuned to formatting text in paragraphs, and making it presentable. Like designing a help page or cleaning up wordy output.
fold
on the other hand, appears more attuned to straight lines of text … perhaps annotated code or something like that.
I am a newcomer to both though, so if there’s another use for either, please let me know. 😉
P.S., does it surprise you that fmt is in coreutils too? It shouldn’t.
Probably worth mentioning that iirc `fold’ is more consistent in its usage across the various BSD’s/Linuces/Unices than `fmt’. Also with reference to this sort of text processing `par’ should be on your list for the P section when you reach it.
It’s on there. Thanks!
I use Mutt as my primary email, so I have this in my ~/.vimrc to format paragraphs to nice readable widths:
map ^P !} fmt -w 72
hmm that looks like a pipe, but it’s a bang.
Interesting. I have
to avoid breaking words in vim, but I hadn’t thought to map the wrap action to a key. Is that similar to CTRL-J in pico or nano?
Pingback: par: After pandoc, par for the course | Inconsolation
Pingback: minime: The 9.8K text editor | Inconsolation
Pingback: Tricks of the trade | Motho ke motho ka botho