lsund
lsund

Reputation: 744

Convenient word wrapping for long paragraphs in vim

I am looking for a technique of writing and editing longer paragraphs in vim. Essentially, what i want is vim to behave like the html textarea where i am currently writing this question.

To some extent I get this behaviour if I set wrap and set linebreak, with j mapped to gj and k mapped to gk. However, when in visual mode, the movements are still line-wise and I know of no convenient way of selecting a part of a long line.

Additionally, I know that the textwidth option automatically breaks lines if the current column of the cursor is above a certain treshold. But if I edit the line from say the middle, the line doesnt break automatically when it gets too long.

I also know I can use gq to format a group of selected lines but it gets tiresome after a while.

What is a technique for good, automatic line wrapping in vim?

Upvotes: 5

Views: 406

Answers (1)

UlfR
UlfR

Reputation: 4395

If you set a in your formatoptions you might get what you whant:

:set formatoptions+=a

See: http://vimdoc.sourceforge.net/htmldoc/change.html#auto-format

...
a   Automatic formatting of paragraphs.  Every time text is inserted or
    deleted the paragraph will be reformatted.  See |auto-format|.
    When the 'c' flag is present this only happens for recognized
    comments.
...

Upvotes: 7

Related Questions