Vim, Markdown, and Unordered List Indentation
I enjoy writing in Vim and neovim, but I've been seeing this curious thing when writing unordered lists.
After writing a unordered line, when I press enter to go to the next line, it indents.
When writing long unordered lines this is great! However, this isn't what I want when making many short unordered lists, such as when copying lists from paper notes.
My initial thought was that this might be related to autoindent
, but it turns out to be related to something called formatoptions
and how it changes handling of comments.
formatoptions
changes how automatic formatting operates in Vim based on character flags which can be individually enabled or disabled.
Repurposed code comments
formatoptions
works because Vim actually treats unordered lists like code comments. It has a feature where it will automatically continue comment styles on the next line for you, which is helpful to reformat code comments with gqq
.
Where does it specify the comment types though?
The output isn't immediately clear, but we can look at help format-comments
to decipher the output:
This shows *
, -
, and +
has having the initial comment string only on the first line ("f"), and must be followed by a blank ("b"). Blockquotes start with >
and can be nested ("n").
formatoptions
help formatoptions
redirects us to fo-table
which describes what each setting does. There's two of particular interest in this case.
By removing the r
and o
settings, the cursor now goes back to the beginning of line, simplifying the creation of quick lists for me.
Disabling at startup
I don't usually use bullet points for long content, so I disable this when Vim sees a Markdown file type.
Other posts I found about this
Another blogger looked into why numbered lists didn't format in a desired way when using gqq
, you might want to have a look. This author looks at formatlistpat
and its effects.