Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get vim to format bulleted lists with correct indentation

Tags:

vim

In vim I can set the textwidth option and then new text is formatted to wrap. I can also use the "gq" command to explicitly wrap text. However, the behaviour with bulleted lists is a bit unexpected to me. The vim docs talk about using bulleted lists with hyphens for the bullets. When I try to do this, it starts okay:

- This is a bulleted list item that
  has been wrapped. It looks good.

However, if I continue onto a third line, it gives up on the indent:

- This is a bulleted list item that
  has been wrapped over more than
two lines. The indentation for lines
after the second is unexpected.

This happens with:

formatoptions=tcq
comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-

Just to be clear, I would like indentation like this:

- This is a bulleted list item that
  has been wrapped over more than
  two lines. I want every line after
  the first to get the same indent.
like image 459
Weeble Avatar asked Sep 02 '11 10:09

Weeble


1 Answers

After further investigation, it looks like I just needed to do "set autoindent" to get the expected behaviour. This seems to work well both for wrapping of text as it it typed and wrapping with the "gq" command.

like image 88
Weeble Avatar answered Oct 15 '22 07:10

Weeble