Say I have a super long line in the VIM editor (say around 300+ characters). How would I break that up into multiple lines so that the word boundaries roughly break at 80 characters?
Example:
This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line
to
This is a really long line
This is a really long line
This is a really long line
This is a really long line
This is a really long line
This is a ...
As a quick and nasty, maybe try the following map:
which says:
Then hitting q and CR will break the line up into chunks on the word boundary.
To split long lines in the complete document without removing already present line breaks, use:
Vim does this very easy (break lines at word boundaries).
I'd suggest you check out
:help gq
and:help gw
.Also setting textwidth (
tw
) will give you auto line break when exceeded during typing. It is used ingq
too, though if disabledgq
breaks on window size or 79 depending on which comes first.By setting format options to include text width vim will automatically break at the tw setting.
I needed to reformat an entire file rather than one line. As Wernsey points out, I could have used 'fmt', but the following sequence in vim did the trick also (borrowing from the various answers here):
I manually inserted '\' (and then CR / tab to format) in each LONGLINE after the last whitespace but before the 80 column. That is to say:
now looks like
and compiles normally.
For solid lines of text highlight the area using v in normal mode, then press
This will add a newline at the end of every 80th character.