我将此文本插入Vim:

t tttt ttttttttt tt tttt tt ttt tttttt-tttt-ttttttt
tttttttttttttttttttttttttttttttttttttttttttttttttttttt ttttt ttt ttt tttttt
ttttttt tttt ttttttt: ttttttt tt ttttttt, ttttttt tt tttttt, tttttt tt ttttttt,
tttttt tt tttttt ttt. t tttttt tt ttt (tttt) ttttttt-tttttt-tt-ttttttt tttttt
for the "tttttt in ttttttt" part of the issue (in the previous week I have
worked on the "objects in objects" part). This part is about making it
possible for the end user to add arrays in objects. First of all I checked
that the current implementation allows putting arrays in objects at least
from the schema passed to the plugin constructor.


,然后我直观地选择所有这些行并按gq。内容变为:

t tttt ttttttttt tt tttt tt ttt tttttt-tttt-ttttttt
tttttttttttttttttttttttttttttttttttttttttttttttttttttt ttttt ttt ttt tttttt
ttttttt tttt ttttttt: ttttttt tt ttttttt, ttttttt tt tttttt, tttttt tt ttttttt,
tttttt tt tttttt ttt. t tttttt tt ttt (tttt) ttttttt-tttttt-tt-ttttttt tttttt
for the "tttttt in ttttttt" part of the issue (in the previous week I have
    worked on the "objects in objects" part). This part is about making it
    possible for the end user to add arrays in objects. First of all I checked
    that the current implementation allows putting arrays in objects at least
    from the schema passed to the plugin constructor.


请向我解释一下为什么在最后四行的开头有空白。第五行上的第一个单词(for)是否有可能启动了for循环(在某些编程语言中),使Vim认为它应该开始一个新的缩进代码块,即使这些行位于未保存的文件或文件中。 Markdown文件?我如何避免这种现象并使gq停止插入该空格?

我的comments设置具有默认值:s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-。您可以在这里看到我的.vimrc文件。

更新:我的foformatoptions)选项的值为tcqformatexprformatprg选项为空。

评论

如果文件已保存/不是新文件,有什么区别吗?

这是相同的行为。

然后,您可以从文本中删除该信息,以使问题更简单。

@GabrielPetrovay,谢谢您的反馈! :-)我更新了问题。

您的“ fo”选项和“ formatexpr”以及formatprg选项是什么?

#1 楼

问题是您在smartindent中设置了~/.vimrcsmartindent选项使Vim缩进时假定您的文本是某种类似于C的编程语言。除其他外,它将for当作关键字对待,并在后面的行中增加了缩进级别。请参见

:help 'smartindent'
:help 'cinwords'