Automatic formatting of paragraphs

From Vim Tips Wiki

When editing a plain-text file (not a program) it can be useful to have lines automatically broken when a certain length is reached. For example, the following command sets the current buffer so that lines longer than 60 characters are broken (a newline is automatically inserted):

You may edit a paragraph consisting of several lines. When finished editing, some lines may be shorter than required. To fix this, in normal mode, type gqip to format the "inner paragraph". In this context, "format" means to reflow the paragraph so that all lines are the optimal length.

Alternatively, format options can be set so that a paragraph is reflowed automatically, after each change. :help auto-format

The following sets the current buffer so that long lines are automatically wrapped on the screen, with lines only breaking at a space. The mappings move the cursor up/down by screen lines instead of by file lines. There is a space following the backslash for the 'breakat' option (the set command requires a backslash before each space). Each long line will be displayed on the screen as multiple lines.