Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format lists in VIM

I would like to find a way to easy format lists in Vim.
I checked PAR and the default formatter of Vim.

p.e.

1. this is my text this is my text this is my text 
2. this is my text this is my text this is my text 
3. this is my text this is my text this is my text 
4. this is my text this is my text this is my text  

and this

- this is my text this is my text this is my text 
- this is my text this is my text this is my text 
- this is my text this is my text this is my text 
- this is my text this is my text this is my text  

when I select the lines and do a default format to 42 with PAR and VIM these are the results:


NUMBERED LIST

formatting with par:
par error:
(42) <= (0) + (50)

formatting with vim:

1. this is my text this is my text this is
my text 
2. this is my text this is my text this is
my text 
3. this is my text this is my text this is
my text 
4. this is my text this is my text this is
   my text 

LIST with '-'

formatting with par:
4 lines filtered (no change)

formatting with vim:

- this is my text this is my text this is
  my text 
- this is my text this is my text this is
  my text 
- this is my text this is my text this is
  my text 
- this is my text this is my text this is
  my text 


Vim does a better job formatting lists but it is not correct as well in a numbered list.
Par does have a lot of troubles formatting lists even when I use the prefix ("p") option like this:
'<,'>!par w42p4dh or '<,'>!par w42p3dh

Does anyone know a good way how to format lists without problems?

like image 673
Reman Avatar asked Jul 18 '11 10:07

Reman


1 Answers

Try set fo+=n. From :help fo-table:

n       When formatting text, recognize numbered lists.  This actually uses
        the 'formatlistpat' option, thus any kind of list can be used.  The
        indent of the text after the number is used for the next line.  The
        default is to find a number, optionally followed by '.', ':', ')',
        ']' or '}'.  Note that 'autoindent' must be set too.  Doesn't work
        well together with "2".                    

        Example: 
                1. the first item
                   wraps 
                2. the second item   
like image 78
Randy Morris Avatar answered Oct 01 '22 12:10

Randy Morris