Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 9 down vote accepted

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*
share|improve this answer
    
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 '10 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 '10 at 5:11
    
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 at 7:42

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\\+
share|improve this answer

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.

share|improve this answer
    
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 '13 at 21:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.