2

I am considering using Vim's auto-format feature (i.e., adding a to formatoptions). However, I can't seem to figure out a combination of options that will give me the configuration that I want. For reference, I am using Vim 8.1 (from May 18, 2018).

I mainly use Vim for coding, and obviously I only want to automatically format comments. When writing comments alone, then formatoptions=acoqr seems to give me exactly what I want.

For code, I also want Vim to force me to break a line after textwidth has been reached, but I do not want it to reformat whole paragraphs when lines are edited. Using formatoptions=t seems to give me the behavior that I want.

However, if I try to combine the two, with formatoptions=acoqrt, then Vim starts to reformat whole blocks of code as well as comments. This seems to contradict the information in :help fo-table, which states:

a       Automatic formatting of paragraphs.  Every time text is inserted or
        deleted the paragraph will be reformatted.  See |auto-format|.
        When the 'c' flag is present this only happens for recognized
        comments.

That is, I would expect that since I am including c in formatoptions, then the auto-formatting behavior should apply to comments, and the ordinary t behavior (inserting newlines but not reformatting whole paragraphs) should apply to code.

Am I missing something? Is this a bug? If so, is there a workaround?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.