【问题标题】:Vim: Textwrap without leading charactersVim:没有前导字符的文本换行
【发布时间】:2014-02-13 21:54:48
【问题描述】:

我正在 VIM 中编写一个项目符号列表,并设置 textwidth=79 来硬换行。当我写这个列表时,我希望每个回车产生一个新的项目符号,并且包装的行没有项目符号。然而,VIM 的做法正好相反(换行上的项目符号,回车后没有项目符号)。我愿意:

* Item 1 - The text for this line is too long and
  so is wrapped to the next line.
* Item 2 - Typing a carriage return after item 1
  should produce the bullet for this item.

但是,VIM 会这样做:

* Item 1 - The text for this line is too long and
* so is wrapped to the next line.
Item 2 - Typing a carriage return after item 1
should produce the bullet for this line.

我打开了自动缩进,关闭了 cindent,并且 formatexpr 是一个空字符串。我理解并喜欢 C 风格 cmets 的自动插入“*”行为,但希望文本文件类型有不同的行为。是否有允许这样做的设置?

【问题讨论】:

  • 你可以使用gq来设置你想要的文本格式(这是我通常做的),但它似乎只适用于-(而不是*
  • 通过设置“cmets=fb:*”和“formatoptions=tcq”,我已经能够非常接近。这可以正确换行,但不会在回车后添加项目符号。我认为在 formatoptions 中添加 'r' 听起来应该这样做,但似乎没有。
  • 我想你用:set fo+=r comments=fb:*得到你想要的一半。

标签: vim word-wrap autoformatting


【解决方案1】:

试试

set formatoptions=tn autoindent
let &formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[*-]\s\)\s*'

formatoptions 中的 n 标志会触发您所追求的列表的格式设置,但 formatlistpat 的默认设置仅处理编号列表。上面添加了*- 的项目符号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 2021-08-27
    • 1970-01-01
    • 2012-04-16
    • 2014-07-31
    相关资源
    最近更新 更多