1

I was interested in the set formatoptions+=a option, but even if the idea of reformatting comment in my code or even markdown text is seducing, I cannot really use the feature because I cannot write something like:

Heading
=======
Some Text

Immediately, Vim will reformat this as follow:

Heading ======= Some Text

What I need to do is insert a blank line between each entry:

Heading

=======

Some Text

Which is not very convenient.

Is there another option that makes this a option a bit smarter?

EDIT

Another example:

/**
 * Heading.
 * A function that does something
 * @param foo Foo
 */

Will be automatically reformatted:

/** Heading. A function that does something @param foo Foo
 */
  • :set fo+=ac works mostly as advertised, just not for Markdown. – Sato Katsura Sep 2 '16 at 8:09
  • Well, it does not work with my example (see my edit) :( – nowox Sep 2 '16 at 8:23
  • It works as advertised. That is, it autoformats comments, not the code. :) – Sato Katsura Sep 2 '16 at 8:32
  • Try :set fo+=w if you don't mind a trailing space to indicate that a paragraph continues. – Antony Sep 2 '16 at 8:39
  • 1
    Cool. Answer added for the archive. – Antony Sep 2 '16 at 9:06
3

If you have a in 'formatoptions',

:set formatoptions+=w

can help with the automatic formatting. It means that lines ending with trailing space indicate that the paragraph continues on the next line. The trailing space is automatically added when the line is broken while typing, editing, or when formatting with gq.

A line without trailing space indicates that a paragraph ends at that line, so hitting <Enter> will end a paragraph.

Note that this doesn't affect the operation of text objects. Commands such as gqap will format a regular paragraph, but the formatting will respect the paragraph boundaries determined by the rules for w.

Your Answer

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

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