为什么我不能阻止vim包装我的代码?

Dav*_*ger 100 vim

我知道必须有一些明显我缺少的东西,但我不能阻止vim包装我的python代码.我:set nowrap像冠军一样进入,但它仍然包裹着.我可以点击:set nowrap分割代码行,所以它似乎插入了真正的回车,我只是不明白为什么或如何阻止它.

Ste*_*ini 110

'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}
Run Code Online (Sandbox Code Playgroud)

如果您将长线自动换行发送到下一行,请尝试

:set textwidth=0 
:set wrapmargin=0
Run Code Online (Sandbox Code Playgroud)

  • 有些插件似乎会覆盖此设置. (12认同)
  • 如果tw和wp仍然无法解决问题请看看SU上的这篇帖子,这有助于我解决我的问题:http://superuser.com/questions/250112/textwidth-0-and-wrapwidth-0-in- vimrc里,本地非存在推崇 (2认同)
  • 从我的`.vimrc`删除`filetype plugin on`为我做了. (2认同)
  • 有了这个答案,您不能使用 `gq` 将段落手动重新对齐为 textwidth。@Engineero 应该是正确的。 (2认同)

Kno*_*kei 75

没有其他答案对我有用(IDK为什么).

:set wrap! 为我做了诀窍(使用GVim for Windows).

  • 这解决了一个稍微不同的问题.`wrap`提供了换行的外观,但没有_actually_将文本分成新行.你可能已经启用了`wrap`,所以`:set wrap!`将它切换掉.您可以使用`:set wrap?`进行检查,它将回显当前值(即`wrap`或`nowrap`). (7认同)
  • 这个解决方案在 Mac OsX 上对我有用。Vim 7.4 版 (2认同)
  • 叮叮叮!在 neovim 中工作 (2认同)

Eng*_*ero 48

set formatoptions-=t应该做的伎俩.set formatoptions+=t将重新打开自动包装.

  • 谢谢!您的解决方案是唯一适合我的解决方案.当我进入插入模式时,vim有时不再插入换行符. (2认同)
  • 对。这是真正的解决方案。 (2认同)

gon*_*332 12

为了防止vim包装长行我在我的下面使用这两行.vimrc:

set nowrap           " do not automatically wrap on load
set formatoptions-=t " do not automatically wrap text when typing
Run Code Online (Sandbox Code Playgroud)


Map*_*psy 10

要禁用换行,您可以输入 :set wrap!或附加此命令~/.vimrc.

  • 这不会影响此问题所涉及的实际换行符的自动插入。 (2认同)

nos*_*nos 8

也许它是设置的文本宽度,当达到一定长度时会自动断行

:set tw=0
Run Code Online (Sandbox Code Playgroud)

如果失败则与例如玩

:set wrap linebreak textwidth=0 
Run Code Online (Sandbox Code Playgroud)

:set virtualedit=insert
Run Code Online (Sandbox Code Playgroud)

  • wrap和linebreak不会在缓冲区中插入实际的行尾,因此这似乎不是他的问题。 (2认同)