The Stripey Site

Vim Tips

Vim has so many features that it can be hard for those new to it enhancements over vanilla Vi that many people find very handy (and that have their existence frequently asked about in comp.editors).

Formatting Paragraphs

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.)

Visual Selection

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.


Feedback is welcome via vim-www@stripey.com. © Copyright 2000 — see copying information for details.