17

The n option of Vim's formatoptions setting will indent the second line of a list item to match the indentation of the first line. However, the third and subsequent lines revert to no indentation, thus:

1. Doing a list. This is my list. I am writing
   a list. It's quite a long list. It's really
long. I can't believe how long it is. And
this just the first item!

2. Another list item.

I'd really like it to indent all the lines, like this:

1. Doing a list. This is my list. I am writing
   a list. It's quite a long list. It's really
   long. I can't believe how long it is. And
   this just the first item!

2. Another list item.

Is this possible, either using Vim's own options, a script, or an external formatting program, such as par?

2 Answers 2

16

I think just setting 'autoindent' should fix that. It does for me.

set ai
5
  • 6
    vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl#14.4
    – akira
    Commented Jan 22, 2011 at 6:45
  • 3
    Works for me too, and I feel stupid for not figuring it out myself, especially seeing as it's right there in the documentation for the 'n' setting! Thanks.
    – Rich
    Commented Jan 23, 2011 at 15:02
  • @akira Yup. I am an idiot. I think my confusion was that because Vim was indenting the second line, I presumed that I had autoindent switched on already, and that the behaviour described in the question was the designed behaviour. I do think the manual could be worded more clearly, though, to benefit idiots such as myself. :)
    – Rich
    Commented Feb 1, 2011 at 17:44
  • See @akira's answer for a more in-depth solution. Commented Mar 28, 2018 at 3:38
  • @Rich, although I am reluctant to call myself stupid, I did go down the same path as you... Thanks for the question and answer.
    – nilo
    Commented Jul 22, 2020 at 15:24
6

in your case i would do this:

 :set autoindent       " just for interactive indenting (see answer of @Rich) 
 :set fo+=2n           " :help fo-table
 :set tw=47            " your text shall wrap at xyz

(the tw=47is important for ..) and then reformat a paragraph by pressing gqap

note: i couldnt reindent the paragrap with = either, maybe someone else figured that out.

1
  • Thank you for reminding me of the a p motion to format lines. I always use the right brace, which is similar. Don't forget you can add a count, for example, format the next three paragraphs: g q 3 }. Commented Mar 28, 2018 at 3:33

You must log in to answer this question.

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