无法解释的gq缩进问题


11

我将此文本插入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)选项的值为tcqformatexpr并且formatprg选项为空。


如果文件已保存/不是新文件,有什么不同吗?
加百利·彼得罗维

这是相同的行为。
silviubogan

然后,您可以从文本中删除该信息,以使问题更简单。
加百利·彼得罗维

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

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

Answers:


18

问题是您已经设置好smartindent~/.vimrc。这些smartindent选项使Vim缩进时假定您的文本是某种类似于C的编程语言。除其他外,它for像关键字一样对待,并在后面的行中增加了缩进级别。看到

:help 'smartindent'
:help 'cinwords'
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.