13

I insert this text in 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.

then I visually select all these lines and press gq. The contents become:

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.

Please explain to me why there is that whitespace at the beginning of the last four lines. Is it possible that the first word (for) on the fifth line, which in some programming languages starts a for loop, makes Vim think it should start a new indented block of code, even if these lines are in an unsaved file or in a Markdown file? How can I avoid this behavior and make gq stop inserting that whitespace?

My comments setting has the default value: s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-. You can see my .vimrc file here.

Update: My fo (formatoptions) option has the value tcq, the formatexpr and formatprg options are empty.

6
  • And if the file is saved/not new, any difference? Commented Nov 24, 2015 at 16:20
  • It is the same behavior. Commented Nov 24, 2015 at 16:24
  • Then you could remove that information from the text in order to make the problem simpler. Commented Nov 24, 2015 at 17:31
  • @GabrielPetrovay, thank you for the feedback! :-) I updated the question. Commented Nov 24, 2015 at 17:34
  • what is your 'fo' option and 'formatexpr' and formatprg option? Commented Nov 24, 2015 at 18:05

1 Answer 1

19

The problem is that you have set smartindent in your ~/.vimrc. The smartindent options causes Vim to assume that your text is some C-like programming language when indenting. Among other things, it treats for like a keyword and gives an extra level of indentation to the line following. See

:help 'smartindent'
:help 'cinwords'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.