antimatter
antimatter

Reputation: 3480

Auto wrap lines in vim without inserting newlines

How do set vim to wrap text without inserting newlines?

Basically:

I can get some of this behavior with:

:set textwidth=80
:set wrap

Except this will insert newlines, and I don't want it to insert newlines. I already tried this but it doesn't work.

Upvotes: 27

Views: 31756

Answers (3)

Acryce
Acryce

Reputation: 701

Here are 3 separate configurations you can use to obtain different line wrapping behaviors while typing in insert mode


Automatically soft-wrap text (only visually) at the edge of the window:

set number # (optional - will help to visually verify that it's working)
set textwidth=0
set wrapmargin=0
set wrap
set linebreak # (optional - breaks by word rather than character)

Automatically hard-wrap text (by inserting a new line into the actual text file) at 80 columns:

set number # (optional - will help to visually verify that it's working)
set textwidth=80
set wrapmargin=0
set formatoptions+=t
set linebreak # (optional - breaks by word rather than character)

Automatically soft-wrap text (only visually) at 80 columns:

set number # (optional - will help to visually verify that it's working)
set textwidth=0
set wrapmargin=0
set wrap
set linebreak # (optional - breaks by word rather than character)
set columns=80 # <<< THIS IS THE IMPORTANT PART

The latter was difficult for me to find

Upvotes: 60

Dorian
Dorian

Reputation: 9055

In my case the line was far too long so I had to do set display+=truncate. Thanks @Friedrich, I'm going to add that to my vimrc

Upvotes: 1

romainl
romainl

Reputation: 196456

Reducing the width of the window to circa 80 characters, set wrap, and set linebreak should satisfy all your requirements.

See :help 'wrap' and :help 'linebreak'.

Upvotes: 6

Related Questions