Vim auto line-break

Eddy picture Eddy · Feb 3, 2012 · Viewed 29.3k times · Source

When I'm writing a long line of text in vim (such as a paragraph in latex), it wraps my text into multiple lines which is good. However, if I then try to navigate these lines with 'j' and 'k' (or the up/down arrows) it will skip the entire paragraph. I fixed this problem by highlighting the paragraph and pressing gq. This inserts line breaks at the end of each line.

My question is, is there a way to automate this, so I don't have to keep highlighting text and pressing gq?

Answer

Ackar picture Ackar · Feb 3, 2012

You can limit the width of a line with the textwidth option (see :help tw).

For example, if you want to limit the width to 80 columns, you can use:

:set tw=80

With this option, when you will type something longer than 80 columns, Vim will automatically insert a newline character.