Why can't I stop vim from wrapping my code?

Vim

Vim Problem Overview


I can't stop vim from wrapping my Python code. If I enter :set nowrap like a champ, but it still wraps.

I can hit J to unite the split lines of code, so it seems like a real carriage return is being inserted. I just don't understand why or how to stop it.

Vim Solutions


Solution 1 - Vim

'textwidth' 'tw'        number  (default 0)
                        local to buffer
                        {not in Vi}
        Maximum width of text that is being inserted.  A longer line will be
        broken after white space to get this width.  A zero value disables
        this.  'textwidth' is set to 0 when the 'paste' option is set.  When
        'textwidth' is zero, 'wrapmargin' may be used.  See also
        'formatoptions' and |ins-textwidth|.
        When 'formatexpr' is set it will be used to break the line.
        NOTE: This option is set to 0 when 'compatible' is set.


'wrapmargin' 'wm'       number  (default 0) 
                        local to buffer
        Number of characters from the right window border where wrapping
        starts.  When typing text beyond this limit, an <EOL> will be inserted
        and inserting continues on the next line.
        Options that add a margin, such as 'number' and 'foldcolumn', cause
        the text width to be further reduced.  This is Vi compatible.
        When 'textwidth' is non-zero, this option is not used. 
        See also 'formatoptions' and |ins-textwidth|.  {Vi: works differently
        and less usefully}

If you refer to auto wrapping of long lines sending them to the next one, try

:set textwidth=0 
:set wrapmargin=0

Solution 2 - Vim

None of the other answers worked for me (IDK why).

:set wrap! Did the trick for me (using GVim for Windows).

Solution 3 - Vim

set formatoptions-=t should do the trick. set formatoptions+=t will turn auto-wrapping back on.

For more information on what you can do with formatoptions, see the docs.

Solution 4 - Vim

For preventing vim from wrapping long lines I use these two lines in my .vimrc:

set nowrap           " do not automatically wrap on load
set formatoptions-=t " do not automatically wrap text when typing

Solution 5 - Vim

To disable line wrap, you can enter :set wrap! or append this command to your ~/.vimrc.

Solution 6 - Vim

Maybe it's the textwidth that's set, which automatically breaks lines when it reaches a certain length Try

:set tw=0

If that fails play with e.g.

:set wrap linebreak textwidth=0 

and

:set virtualedit=insert

Solution 7 - Vim

Vim may have to be in vi-compatible mode.

Solution 8 - Vim

Open vimrc_example.vim (Yes, this is the file in Vim74) and set textwidth=0.

Solution 9 - Vim

On macbook pro I outcommented in .vimrc the line

autocmd FileType text setlocal textwidth=78

so it became

"  autocmd FileType text setlocal textwidth=78

.

(I installed a version of vim via homebrew.) This helped for all .txt files.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid BergerView Question on Stackoverflow
Solution 1 - VimStefano BoriniView Answer on Stackoverflow
Solution 2 - VimKnomo SeikeiView Answer on Stackoverflow
Solution 3 - VimEngineeroView Answer on Stackoverflow
Solution 4 - Vimgon1332View Answer on Stackoverflow
Solution 5 - VimMapsyView Answer on Stackoverflow
Solution 6 - VimnosView Answer on Stackoverflow
Solution 7 - VimmcandreView Answer on Stackoverflow
Solution 8 - VimBobbyView Answer on Stackoverflow
Solution 9 - Vimfeli_xView Answer on Stackoverflow