vim paragraph formatting to wrap at 80 characters
Forcing selected text to be limited to 80 characters within vim is fairly straightforward.
Just do this:
- Set the text width.
- Select desired lines.
- Reformat selected text.
Here's the breakdown in more detail.
From within vim, first set the text width setting so that vim knows how to format the selected text:
:set textwidth=80
Selecting the text can be done a number of ways, so for this example, let's say my cursor was on the first line of a paragraph that I wanted to format. The cursor can be on any column of that line for this to work. I would then do this to select that paragraph:
Shift-v }
Then I would reformat that paragraph, by just typing this:
gq
For more UNIX tips, please check out
Learning the UNIX Command Line.
Enjoy,
Chip
Related protips:
Written by Chip Castle
Related protips
1 Response
Or if the paragraph is separated with newlines simply "gqad" will do it without selecting anything.
But thanks for the Shift-v way, I was looking for that, since often it arent actually well separated paragraphs due to HTML or LaTeX encodings around.