Vim Tips Wiki
Advertisement

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created May 1, 2012 · complexity basic · version 7.0

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

Comments[]

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?


Related tips:

From :help fo-table:

w Trailing 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)
Yes, I agree we need a tip spelling that out. I've added tips 347 and 579 to the above list. Tips 347, 440, 579, 850 need to be cleaned up, and it is likely that the information above should be in one of those. If necessary, the title of the other tips should be changed. No one has explained what w is doing. JohnBeckett (talk) 10:26, October 14, 2012 (UTC)
Advertisement