2024-07-07 10:00:02

如何停止断行在vim

我喜欢长线显示在多个终端线;我不喜欢vim插入换行到我的实际文本。我应该修改。vimrc的哪一部分?


当前回答

:设置tw = 0

VIM不会自动插入换行符,但会保持换行。

其他回答

正确的是,set nowrap将允许你粘贴一个长行,而不需要vi/vim添加换行符,但这样行就不会被视觉上的换行以方便阅读。相反,它只是一个长长的行,你必须滚动。

要使行在视觉上换行但不插入换行符,请设置wrap(这可能是默认设置,因此不需要设置)并设置textwidth=0。

在某些系统上,textwidth=0的设置是默认的。如果您发现情况并非如此,请将set textwidth=0添加到您的.exrc文件中,以便它成为所有vi/vim会话的用户默认值。

我不确定我完全理解,但你可能正在寻找'formatoptions'配置设置。试着这样做:set formatoptions-=t。t选项将插入换行符,使文本按textwidth设置的宽度换行。你也可以把这个命令放在你的.vimrc中,只是去掉冒号(:)。

使用:set nowrap ..效果好极了!

我喜欢在多个终端行上显示长行

这种可视/虚拟行换行是由wrap window选项启用的:

:set wrap

默认情况下,这将在窗口中不适合的第一个字符处换行。这意味着如果窗口边界位于单词的中间,它将自动换行。要将其更改为按单词边界换行,您还可以:

:set linebreak

这将导致换行只对换行符设置中的字符进行换行,该设置默认为空格、制表符和一小组标点符号。

:set breatat
  breakat= ^I!@*-+;:,./?

我不喜欢vim插入换行到我的实际文本。

要关闭物理行换行,请清除textwidth和wrapmargin缓冲区选项:

:set textwidth=0 wrapmargin=0

如果像我一样,你在Windows上运行gVim,那么你的.vimrc文件可能是另一个“示例”Vimscript文件,它会自动设置文本文件的文本宽度(在我的例子中是78)。

我在Vi和Vim Stack Exchange站点上回答了一个类似的问题——如何停止gVim在第80列包装文本:

In my case, Vitor's comment suggested I run the following: :verbose set tw? Doing so gave me the following output: textwidth=78 Last set from C:\Program Files (x86)\Vim\vim74\vimrc_example.vim In vimrc_example.vim, I found the relevant lines: " Only do this part when compiled with support for autocommands. if has("autocmd") ... " For all text files set 'textwidth' to 78 characters. autocmd FileType text setlocal textwidth=78 ... And I found that my .vimrc is sourcing that file: source $VIMRUNTIME/vimrc_example.vim In my case, I don't want textwidth to be set for any files, so I just commented out the relevant line in vimrc_example.vim.