9

I want to reformat my file so the max line width is 79. I did :set tw=79 and gggqG and the results weren't what I expected. When a line is less than 79 col, characters from the line below it move up and lines with over 79 col don't break into two lines.

edit: Well I was semi-mistaken in that it DOES break lines over 79 except in the line with asterisks.

--CONVENTIONS**************************************************************************************

In addition it still moves characters up when the line has <79.

franzlorenzon
  • 5,845
  • 6
  • 36
  • 58
deadghost
  • 5,017
  • 3
  • 34
  • 46
  • It works for me following your instructions, but check that lines are breakable. For example, urls will keep their original format after that width. – Birei Jan 11 '12 at 13:30

2 Answers2

9

One possible solution, although not the best one.

Undefine formatexpr and let external fold program to format your text to 79 characters width.

:set formatexpr=
:set formatprg=fold\ -w\ 79

And now:

gg              # Go to beginning of file.
gq              # Format until...
G               # End of file.

And last remove those carriage returns (^M):

:%s/\r//g

In my test it changed some accented characters and some other lines were mangled, but try it yourself. Else you may write your own format function and use it with formatexpr option.

Birei
  • 35,723
  • 2
  • 77
  • 82
1

Put empty line between different paragraphs. Then do the reformat.

kev
  • 155,172
  • 47
  • 273
  • 272
  • It doesn't send characters up a line when I add empty lines between each pair of lines however it doesn't actually split my longer lines into 79 col lines. – deadghost Jan 11 '12 at 13:25