Mind your t, c, and q

Posting this so someone else doesn’t have to go through the trouble I went through.

I was having a problem reflowing comments in vim. Whenever I reflowed something like:

# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor ...

I would get something like this:

# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor ...

Which was not what I wanted. I spent about an hour trying to figure out what the problem was, until I stumbled across this line in my .vimrc:

set formatoptions=l

After reading the vim help, it occurred to me why the default .vimrc was giving me the right result (formatted comments) while my .vimrc wasn’t. By default, vim sets format options to tcq. Here’s what each of those mean:

t Auto-wrap text using textwidth
c Auto-wrap comments using textwidth, inserting the current comment
 leader automatically.
q Allow formatting of comments with "gq".
 Note that formatting will not change blank lines or lines containing
 only the comment leader. A new paragraph starts after such a line,
 or when the comment leader changes.

And once I set the formatoptions line to ‘tcql’, now everything works perfectly.

And now you know. :)