Created
June 20, 2011 02:23
-
-
Save vim-voom/1035030 to your computer and use it in GitHub Desktop.
Markdown folding for Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" folding for Markdown headers, both styles (atx- and setext-) | |
" http://daringfireball.net/projects/markdown/syntax#header | |
" | |
" this code can be placed in file | |
" $HOME/.vim/after/ftplugin/markdown.vim | |
" In Markdown, setext-style overrides atx-style, so we first check for an | |
" underline. Empty lines should be ignored when underlined. | |
func! Foldexpr_markdown(lnum) | |
let l1 = getline(a:lnum) | |
if l1 =~ '^\s*$' | |
return '=' | |
endif | |
let l2 = getline(a:lnum+1) | |
if l2 =~ '^=\+\s*$' | |
return '>1' | |
elseif l2 =~ '^-\+\s*$' | |
return '>2' | |
elseif l1 =~ '^#' | |
return '>'.matchend(l1, '^#\+') | |
else | |
return '=' | |
endif | |
endfunc | |
setl foldexpr=Foldexpr_markdown(v:lnum) | |
setl foldmethod=expr | |
"---------- everything after this is optional ----------------------- | |
" change the following fold options to your liking | |
" see ':help fold-options' for more | |
setl foldenable | |
setl foldlevel=0 | |
setl foldcolumn=0 | |
" text of closed fold | |
" shows the first line as is, plus fold level and the number of hidden lines | |
setl foldtext=getline(v:foldstart).'\ \ \ /'.v:foldlevel.'...'.(v:foldend-v:foldstart) | |
"-------- other buffer- and window-local settings to override defaults | |
" setl wrap list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment