【问题标题】:Fixing line overflow in paragraph, given a set textwidth in VIM修复段落中的行溢出,给定 VIM 中的设置文本宽度
【发布时间】:2013-11-03 03:49:13
【问题描述】:

假设我的 .vimrc 具有以下配置:

set textwidth=10

在文件中输入以下内容:

This is a 
sentence
word wraps
just fine
at 10 
chars.

当我输入这句话时,VIM 会实时自动换行并阻止我通过我设置的标记。但是,我发现自己遇到的一个常见问题是添加更多内容。我忘记了上一段中的一个词,“sentence THAT word wraps”。

所以我回去添加它。

This is a
a sentence that, suddenly, doesn't
word wrap
just fine
at 10
chars.

如果我现在想解决这个问题(所有行都低于我设置的 10 个字符限制),我必须找到 10 个字符的位置,点击 RETURN(向下移动额外内容),然后找到 10字符点在下一行,按 RETURN,依此类推。

这个场景在我的程序和代码中的函数序言中经常出现(我通常使用 73 个字符的行限制),因为我发现自己以后必须添加更多解释或内容。

有没有快速/简单的方法来解决这个问题?

还有:

我在我的.vimrc 中有这个来突出显示文本宽度违规者:

" highlight anything past the 73 character limit
augroup vimrc_autocmds
    autocmd Filetype cpp autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#592929
    autocmd Filetype cpp autocmd BufEnter * match OverLength /\%73v.*/
augroup END

也许我也可以在这里添加一些东西?

【问题讨论】:

  • :set formatoptions?的输出是什么

标签: vim vim-plugin


【解决方案1】:

您可以使用gq 命令重新格式化受影响的行。通常,gqap(格式段落)会使用视觉模式或动作。

你也可以在输入 :set formatoptions+=a 的同时让 Vim 不断地重新格式化,但这对我来说从来都不是很好。

【讨论】:

  • 太棒了,正是我需要的!
【解决方案2】:

:help fo-table 报告的 Vim 手动输入:

l       Long lines are not broken in insert mode: When a line was longer than
        'textwidth' when the insert command started, Vim does not
        automatically format it.

由于您在评论中说formatoptions 包含字母l,您应该使用以下命令关闭此选项:

:set formatoptions-=l

要修复现有的行,正如 Ingo 已经建议的那样,您可以使用 gq 命令,该命令将遵循 textwidth 设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    • 1970-01-01
    • 2011-07-14
    • 2011-05-08
    相关资源
    最近更新 更多