[ Jonathan McPherson's home page ]
 

par, the Paragraph Formatter

par is an extremely well-written and intelligent paragraph formatter that almost no one knows about. It makes it easy to write enviably well-formatted plain text e-mails and is also helpful with source code. Some ways in which par surpasses other paragraph formatters:

  • par preserves prefixes and suffixes on each line. This means that it adds the infamous > marks to e-mails when necessary as it breaks lines. It also preserves suffixes, which is invaluable when you have text surrounded by a "box" of characters.
  • par uses a dynamic programming algorithm to find an optimal set of line breaks. Most other formatters, like the Unix standard fmt, use a greedy algorithm that tends to generate more ragged right edges of formatted text.
  • par can fully justify text rather than simple left- or right- justification.
  • par is quite flexible and has a host of command-line options that allow you to make it do just about anything you'd like.

Getting par

par compiles under just about any Unix. You can read more about it or get it here:

http://www.nicemice.net/par/

Using par in vim

To filter part of a file through par using vim, first select the lines you wish to filter (type V to begin linewise selection mode). Then, while the lines are selected, type:

:!par

(That assumes that par is installed in a directory in your $PATH.) Vim will expand the above to :'<,'>!par, which is the command you actually want to execute -- '< and '> are markers that represent the first and last lines currently selected.