Wikia

Vim Tips Wiki

80 character line wrap without broken words

Talk0
1,613pages on
this wiki
Revision as of 21:09, October 10, 2012 by Gay Karate Man (Talk | contribs)

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)

Around Wikia's network

Random Wiki