Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown lists in Vim, automatically new bullet on CR

Tags:

vim

markdown

Im using Markdown in Vim to write a lot of text. I'm wondering if its possible to make Vim automatically start the next line with a bullet * or - if I'm currently working on a text line in the list, and then presses enter ?

A lot of other text editors does this (e.g. Notational Velocity) so it would be great if this is possible in Vim as well.

What I want Vim to do:

- List element 1
- List element 2[press enter]
- (We are automatically here, with the bullet)

And I only want this for Markdown files.

Hope you understand! Thnx!

like image 880
eivindml Avatar asked Jan 30 '12 15:01

eivindml


1 Answers

you need to set several vim variables to do it.

let's take '-' as example:

:set com=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,b:-

here the last 'b:-' is important. it means, vim will think '-' and a space([tab] too) as comment leader, and will automatically added after you pressed Enter or o (normal mode). this set by :set formatoptions . see following lines.

you could check

:h comments
:h format-comments 

for details

:set formatoptions=tcroqln

here 'r' and 'o' are used for your requirement.

:h formatoptions 
:h fo-table

for details

EDIT

for adding markdown filetype. many resources on the net. simply gave a shot on google, got one:

http://technicalpickles.com/posts/using-markdown-in-vim/

change au to settings above, should work.

like image 200
Kent Avatar answered Nov 16 '22 04:11

Kent