Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Textwrap without leading characters

I am writing a bulletted list in VIM, and have set textwidth=79 to hard wrap the lines. As I write the list, I would like for each carriage return to produce a new bullet and for the wrapped lines to not have bullets. However, VIM is doing the opposite (bullets on wrapped lines, no bullets after carriage return). I would like:

* Item 1 - The text for this line is too long and
  so is wrapped to the next line.
* Item 2 - Typing a carriage return after item 1
  should produce the bullet for this item.

However, VIM does this:

* Item 1 - The text for this line is too long and
* so is wrapped to the next line.
Item 2 - Typing a carriage return after item 1
should produce the bullet for this line.

I have autoindent on, cindent off, and formatexpr is an empty string. I understand and like the auto-inserted '*' behavior for C-style comments, but would like different behavior for text filetypes. Is there a setting that allows this?

like image 638
FazJaxton Avatar asked Feb 13 '14 21:02

FazJaxton


1 Answers

Try

set formatoptions=tn autoindent
let &formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[*-]\s\)\s*'

The n flag in formatoptions triggers the formatting of lists that you are after but the default setting of formatlistpat only handles numbered lists. The one above adds bullets of either * or -.

like image 77
Geoff Reedy Avatar answered Oct 07 '22 17:10

Geoff Reedy