Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am using Vim with formatoptions +=a as described in Vim: word wrap for documents to format lines automatically while I write documents, expecially Markdown documents.

My problem is that Vim wants to reformat also bullet lists because there is blank line between each bullet point.

What happes is that vim reformats

This is wath we will do:

* task 1,
* task 2,
* task 3.

into

This is wath we will do:

* task 1,   task 2,   task 3.

(I also do not understand why the asterisks disappear in this reformatting process.)

How can I make Vim stop reformatting these lists?

share|improve this question
    
The asterisks disappear because Vim mistaken them for comments leaders. –  gioele Feb 9 '12 at 15:59

2 Answers 2

up vote 1 down vote accepted

Try this:

  • add n to formatoptions so vim recognizes lists (:set fo+=n)
  • set the formatlistpat option to recognize asterisk as bullets (set flp+=\\\|^\\*\\s*) (note that number of backslashes depends on your magicness level).

It's not perfect based on my testing but it seems to be close.

share|improve this answer
    
Thank you, it works well enough. –  gioele Feb 10 '12 at 10:17

Is the filetype option set to markdown when you are editing your Markdown files? You can use :verbose set filetype? to inspect the current value.

When you have run :filetype plugin on (e.g. from your .vimrc), and filetype is set to markdown, Vim will source $VIMRUNTIME/ftplugin/markdown.vim which will set some options (comments, formatlistpat, and formatoptions) that should help with formatting Markdown list items.

Note: The common Markdown filename pattern *.md is actually mapped to the modula2 filetype by $VIMRUNTIME/filetype.vim. You may want to override this setting if you commonly use this filename pattern for your Markdown files. You could do that by putting this in your .vimrc file:

autocmd! filetypedetect BufNewFile,BufRead *.md setfiletype markdown

Alternatively, you could add a modeline to each file:

<!-- vim: set filetype=markdown : -->
share|improve this answer
    
tpope's syntax files (the one I am using) set formatlistpath in github.com/tpope/vim-markdown/blob/master/ftplugin/markdown.vim . For some reasons it looks that the ftplugin is not loaded... –  gioele Feb 10 '12 at 10:17
    
That vim-markdown plugin should be sufficient, but you need to enable its functionality (and that of other filetype plugins) with :filetype plugin on. See :help :filetype-plugin-on. –  Chris Johnsen Feb 10 '12 at 22:08

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.