11

While Vim supports automatic indenting in lists, the default setting only covers ordered lists, starting with digits, such as:

1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
   tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
2. veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
   commodo consequat.

I have not been able to figure out how to extend this to unordered, bulleted lists, such as:

* Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
* veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
  commodo consequat.

Changing the formatlistpat RegEx did not lead to the desired results (indeed, it even broke ordered lists).

Kazark
  • 3,509
AnC
  • 334

4 Answers4

12

Knowing what you tried to set the value to would help, but I'm guessing you didn't properly escape the backslashes.

The default value is

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

but to actually set that value (in your vimrc or at the cmdline) you have to use

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

This is explained in :help option-backslash. A simple modification to allow formatlistpat to work with * delimited, unordered lists would be

set formatlistpat=^\\s*[0-9*]\\+[\\]:.)}\\t\ ]\\s*
jamessan
  • 1,071
3

In addition to what jamessan wrote (in particular his formatlistpat suggestion for working with * lists), it is important to have the 'c' option (comment formatting) unset in formatoptions:

set formatoptions-=c

otherwise Vim gets confused between the formatting of * bulleted lists and the formatting of comments. You end up with an extra * on the 2nd and following lines.

Blixtor
  • 31
  • 1
2

I am writing a new answer to this question because I had to combine multiple answers from this question and this other question to make this work. Here is my final configuration.

set formatlistpat=^\\s*[0-9*]\\+[\\]:.)}\\t\ ]\\s*
set formatoptions-=c
set comments-=mb:*
merlin2011
  • 2,117
1

I had some trouble getting lists like a) recognized, so I'll post my solution here:

" Recognise lists like 1), 1., a), a., and so on
" Note that | need to be escaped AND preceeded by a literal backslash
set formatlistpat=^\\s*\\([0-9]\\+\\\|[a-z]\\)[\\].:)}]\\s\\+
RobM
  • 755