How can I justify plain text in Linux?
you need par
(official website, source code, package status on Repology)
e.g. to get it on ubuntu, do:
sudo aptitude install par
to justify text.txt
(at the width of 80 chars), saving in newtext.txt
:
par j1w80 < text.txt > newtext.txt
to use par in vim or gvim:
:set formatprg=par\ j1w80
then highlight the text you want to format and use the gq
command.
for more information, see man par
fmt
is the old-school solution
From the man page:
fmt [-cmnps] [-d chars] [-l num] [-t num] [goal [maximum] | -width | -w width] [file ...]
and
The goal length defaults to 65 and the maximum to 10 more than the goal length. Alterna- tively, a single width parameter can be specified either by prepending a hyphen to it or by using -w. For example,
fmt -w 72'',
fmt -72'', and ``fmt 72 72'' all produce identical output.
You can do this in emacs using fill-paragraph
or fill-region
(fill docs).
You need to pass a numeric prefix argument. The default fill column is 70.
Select the text to fill and do M-3 M-x fill-region
.
I set the fill column to 53 for your sample text and got:
These phantasmic balls have some strange properties,
some neat, some interesting, and others just
indicative of lazy design. They're almost all caused
by the same design flaw: The game treats them too
much like regular balls.