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).

4 Answers 4

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*
7
  • Indeed, that works - many thanks! I thought I had properly escaped everything (even reduced the pattern's complexity), but apparently I was wrong. I might have escaped the asterisks, which would explain my troubles...
    – AnC
    Jan 22, 2010 at 21:42
  • 2
    As explained in the help for [] it is faster to use [[:digits:]*] or [\d*] rather than [0-9*]
    – Aditya
    Oct 21, 2010 at 5:11
  • 1
    One could sidestep the quoting issue by using let rather than set, e.g: let &formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[*-][\t ]\)\s*'. (This adds support for * and - as bullets, in addition to numbers.)
    – wjv
    May 2, 2014 at 7:42
  • @wjv I've tried your solution and it works for - lists, but not with asterisks. Any idea what could cause this?
    – languitar
    Jun 3, 2015 at 11:25
  • @wjv seems the * inside the comments variable, despite being the middle part of a three-part comment, lets vim confuse the asterisk with a line comment.
    – languitar
    Jun 3, 2015 at 12:42
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.

1
  • Not only that, but the q (allow formatting of comments with gq) formatoptions flag can cause problems when formatting with gq. +1
    – Kazark
    Mar 13, 2013 at 21:29
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:*
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\\+

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .