Vim:无前导字符的文本换行

11

我正在使用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.

我开启了自动缩进(autoindent),关闭了C样式的缩进(cindent),并且formatexpr是一个空字符串。我理解并喜欢C样式注释中自动插入星号的行为,但是想要不同的行为用于文本文件类型。有没有设置可以允许这样做?


你可以使用 gq 来按照你想要的格式化文本(这是我通常做的),但它似乎只适用于 -(而不是 *)。 - Martin Tournoij
我已经通过设置“comments=fb:*”和“formatoptions=tcq”接近了目标。这样可以正确换行,但是在回车后没有添加符号。我认为将“r”添加到formatoptions中似乎应该可以实现这一点,但事实并非如此。 - FazJaxton
我认为使用 :set fo+=r comments=fb:* 可以满足你一半的需求。 - benjifisher
1个回答

1

尝试

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

在 formatoptions 中使用 n 标志会触发所需的列表格式化,但 formatlistpat 的默认设置仅处理编号列表。上面的设置会添加圆点符号,可以是 *-

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接