markdown folds

13 views
Skip to first unread message

Alexandre Leray

unread,
Jan 7, 2011, 10:16:09 AM1/7/11
to vim...@googlegroups.com
Hi,

I'm maintaining markdown files using vim, and some of them are becoming
quite large. I'm looking for a vim plugin to fold the files according to
their H1-H6 markers (I'm using === and --- for h1 and h2). Do you know
any script to do that?

Best,

Alexandre Leray

Vlad Irnov

unread,
Jan 7, 2011, 5:53:11 PM1/7/11
to vim_use


On Jan 7, 10:16 am, Alexandre Leray <alexan...@alexandreleray.com>
wrote:
May I suggest my VOoM plugin:
http://www.vim.org/scripts/script.php?script_id=2657
The latest version can outline Markdown
:Voom markdown
It's more powerful than just folding.

But if you must have folding, it should be easy to write a folding
expression.
Here is my attempt, not tested very well:

" folding for Markdown headers, both style
" http://daringfireball.net/projects/markdown/syntax#header
setl foldmethod=expr
setl foldexpr=Foldexpr_markdown(v:lnum)
func! Foldexpr_markdown(lnum)
let l1 = getline(a:lnum)
" ignore empty lines
if l1 =~ '^\s*$'
return '='
endif
" next line is underline
let l2 = getline(a:lnum+1)
if l2 =~ '^=\+\s*'
return '>1'
elseif l2 =~ '^-\+\s*'
return '>2'
" current line starts with hashes
elseif l1 =~ '^#'
return '>'.matchend(l1, '^#\+')
" keep previous foldlevel
else
return '='
endif
endfunc


Alex

unread,
Jan 8, 2011, 8:38:01 AM1/8/11
to vim_use
Hi, and thanks a lot!

VOom is not what I had in mind but it seems to be even better! Also
thanks for the snippet for folding; I will give a look at it as I'm
still interested in the folding method.

Best,

Alex
Reply all
Reply to author
Forward
0 new messages