tags:

views:

132

answers:

3

I just realized that VIM 7.3 has built-in support for highlighting Markdown files. Excellent. However, it doesn't fold on the headings.

Can any offer suggestions on how to get this working?


Alternatively, I'm using Markdown only as a way to get simple structured text. If there is a better alternative format, please also suggest. But not sure I dig TVO or VimOutliner.

+1  A: 

The only way how I get folding to work in markdown, was't very elegant, :set fdm=marker and use html comment tag

 <!-- My folding {{{1 -->

more help :help folding

kfl62
A: 

Here is a try at a recursive header folding rule. It doesn't include the underline style of Markdown header, but I'm guessing those would be awkward for your purposes anyway.

Put the following code into your .vimrc:

au FileType markdown syn region myMkdHeaderFold
        \ start="\v^\s*\z(\#{1,6})"
        \ skip="\v(\n\s*\z1\#)\@="
        \ end="\v\n(\s*\#)\@="ms=s-1,me=s-1
        \ fold contains=myMkdHeaderFold

au FileType markdown syn sync fromstart
au FileType markdown set foldmethod=syntax
Jander
A: 

I had the same question, and played around with Jander's nice solution. The only problem is that by defining folding using syntax, you lose any Markdown syntax highlighting.

Given that you might be interested in alternate markups, I would suggest using reStructuredText, and the amazing Vst vim extension. It does folding very nicely. Rst is much more powerful than Markdown.

erick
I ended up using Viki instead. It's not Markdown, but it does folding properly.
Muchin
I suppose the nice thing about Rst is that it can then be used for many other purposes, such as a Jekyll wiki, HTML, LaTex..
erick