【问题标题】:How do I change autoformat in vim?如何在 vim 中更改自动格式化?
【发布时间】:2012-11-29 11:13:02
【问题描述】:

我使用自动格式化 (textwidth = 72) 在 vi​​m 中编写电子邮件。

问题是每次我写一个列表或短语时,vim 都会将它加入到上面的行中。

p.e.

These are my options:
- option nr. 1

当我写“-”时,“-”立即与上面的短语相连:

These are my options: -

当我使用其他类型的列表时也是如此。编号列表或列表前的其他符号。

当我写短于 72 个字符的短语时也是如此

This is my text.
This is my text on the 2nd line.

自动格式化将其更改为:

This is my text. This is my text on the 2nd line.

如何改变这种行为?
我只想在前 72 个字符中没有回车 <CR> 时格式化长行。
如果有<CR>,它必须在那里中断。

【问题讨论】:

  • 所以你不想摆脱自动格式化,但是 vim 应该如何知道你想在哪里中断?
  • 我想在 72 个字符处中断(即我在 vimrc 中添加的 textwidth)。因此,如果我写的一行比 72 长,它必须在 72 处中断并继续下面的行。如果我写一行 p.e. 60 个字符,然后按我键盘上的 enter 键转到下面的行 Vim 必须保持原样。

标签: vim scripting format autoformatting


【解决方案1】:

:help autoformat 给出了一些有用的提示:

  • 您需要正确定义段落。最简单的段落是 用空行分隔。当没有分隔空行时,考虑 使用 'w' 标志并在每行的末尾添加一个空格 除最后一段以外的段落。

所以,要么:setlocal fo+=w,要么关闭自动格式化(可能只是暂时的,使用快速切换映射)。

【讨论】:

  • Ingo, :help autoformat --> E149:抱歉,自动格式化没有帮助。
  • :help auto-format;其他标签拼写显然只在最新的运行时更新中可用。
  • @Ingo Karkat 仍然有自动格式化的问题。 autoformat 不能识别 formatlistpat 中设置的列表吗?这些是我的设置 let &formatlistpat='^\s*\([-*]\|\d\+[.)]\|\a\+[.)]\)\s\+'set formatoptions=tcqronw
猜你喜欢
  • 1970-01-01
  • 2017-10-07
  • 2014-11-30
  • 1970-01-01
  • 2011-01-22
  • 1970-01-01
  • 2013-04-23
  • 2011-05-23
相关资源
最近更新 更多