Indentation for plain text bulleted lists in Vim

I often write text with a format like this in Vim—

- talking point 1

- talking point 2 ....
continue on point 2

Ideally, I would hope Vim could auto align it for me such as:

- talking point 1

- talking point 2 
  continue on point 2

Is this possible?


Solution 1:

I've got this in my .vimrc:

set comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-,fb:[+],fb:[x],fb:[-]

If I remember correct, add this line in your .vimrc and the job will be done:

set comments +=fb:-

For a detailed explanation try:

:help comments

Solution 2:

If you have the n flag set in formatoptions (e.g. with set fo+=n), Vim already knows how to format lists with numeric bullets. formatlistpat (short name flp) is the regex Vim uses to match this, so what you need is to enhance that regular expression. This should do the trick for you (but only adds support for - bullets):

set formatlistpat=^\\s*\\(\\d\\+[\\]:.)}\\t\ ]\\|-\\)\\s*

Sorry for the backslash headache there. Doing set flp? shows more clearly what the regex looks like:

formatlistpat=^\s*\(\d\+[\]:.)}\t ]-\)\s*

For more information, see this post.