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.
If your goal, while typing in insert mode, is to 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)
If your goal, while typing insert mode, is to 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)
If your goal, while typing in insert mode, is to 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 took me 2-3 significant Internet-scouring sessions to find from here (give 'er a read - it's very well-written): https://agilesysadmin.net/how-to-manage-long-lines-in-vim/
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'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With