How to wrap all lines at 80 characters without breaking any words, and preserve shorter lines:
:set formatoptions+=w :set tw=80 gggqG
Use the following mapping to format the current paragraph:
:nnoremap Q gqip
What problem are you trying to solve? Inserting hard line breaks in a line which is too long never wraps in the middle of the word. Were you having trouble with the 'wrap' option? Did you not know about it's partner 'linebreak' option?
- 38 Move cursor by display lines when wrapping
- 308 Move through wrapped lines
- 440 Automatic formatting of paragraphs (mentions
- 850 Automatic word wrapping
- 989 Word wrap without line breaks (mentions
From :help fo-table:
wTrailing white space indicates a paragraph continues in the next line. A line that ends in a non-white character ends a paragraph.
I'm not familiar with the
w option and am not sure if it is doing anything useful in this tip. I guess this tip should be merged to one of those above. JohnBeckett 03:09, May 16, 2012 (UTC)
- I think what's useful about this tip is that it explains how to hard-wrap text that's already entered. The "wrap" option only will work on text as it's entered, if I remember correctly. I'm often editing HTML with extremely long lines, so I use this fairly often.Gay Karate Man (talk) 21:09, October 10, 2012 (UTC)