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.

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

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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