When working with plain text,
Vim is capable of rejigging
the line breaks to keep paragraph formatting where things have been
inserted and deleted. The keystrokes
gq do this. For example
gqap reformats the current paragraph (like
<Ctrl>+J does in
Pico), and
gqG
reformats all paragraphs to the end of the file. For more information on
gq and the ‘text objects’ that can follow it, see:
:help gq
:help text-objects
(For how to make
Vim work even better with plain text files,
see the
formatting page.)
Sometimes it is easier to select text visually than by counting lines,
paragraphs, or whatever.
Vim can do this. Simply tap
v to enter visual mode, then use the usual motion keystrokes
to extend the selection. Once a selection has been made, the commands
that normally precede a motion will operate on that selection. For
example,
y will yank it and
d will delete it.
The variant V selects by lines, and <Ctrl>+V
selects rectangular blocks that span lines. For example, to select a few
lines and reformat them, press V then j (or
<Down>) the required number of times to extend the
selection then gq to perform the reformatting on those lines.