tags:

views:

172

answers:

1

I know there are ways to automatically set the width of text in vim using set textwidth (like http://stackoverflow.com/questions/235439/vim-80-column-layout-concerns). What I am looking for is something similar to = (the indent line command) but to wrap to 80. The use case is sometimes you edit text with textwidth and after joining lines or deleting/adding text it comes out poorly wrapped.

Ideally, this command would completely reorganize the lines I select and chop off long lines while adding to short ones. An example:

long line is long!
short

After running the command (assuming the wrap was 13 cols):

long line is
long! short

If this isn't possible with a true vim command, perhaps there is a command-line program which does this that I can pipe the input to?

EDIT: thanks michael, after googling that command I found this reference which has some more options: http://www.cs.swarthmore.edu/help/vim/reformatting.html

+4  A: 

Set textwidth to 80, move to the start of the file (can be done with Ctrl-Home or gg), and type gqG.

gqG formats the text starting from the current position and to the end of the file. It will automatically join consecutive lines when possible. You can place a blank line between two lines if you don't want those two to be joined together.

Michael Madsen