X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/20704d86a0ae043664f3facca84a61eded05de6e..17be3cdaeaedc796fade2c3d93d31fef56a68934:/after/ftplugin/mkd.vim?ds=inline diff --git a/after/ftplugin/mkd.vim b/after/ftplugin/mkd.vim index f04ae2b..6026ae8 100644 --- a/after/ftplugin/mkd.vim +++ b/after/ftplugin/mkd.vim @@ -7,8 +7,8 @@ " original version from Steve Losh's gist: https://gist.github.com/1038710 func! Foldexpr_markdown(lnum) - if (a:lnum == 0) - let l0 = getline(a:lnum) + if (a:lnum == 1) + let l0 = '' else let l0 = getline(a:lnum-1) endif @@ -29,23 +29,28 @@ func! Foldexpr_markdown(lnum) elseif l0 =~ '^#' " current line starts with hashes return '>'.matchend(l0, '^#\+') - elseif a:lnum == 1 - " fold any 'preamble' - return '>1' else " keep previous foldlevel return '=' endif endfunc -setlocal foldexpr=Foldexpr_markdown(v:lnum) -setlocal foldmethod=expr - -"---------- everything after this is optional ----------------------- -" change the following fold options to your liking -" see ':help fold-options' for more -setlocal foldenable -setlocal foldlevel=0 -setlocal foldcolumn=0 -set foldmethod=expr -set foldopen-=search + +if !get(g:, "vim_markdown_folding_disabled", 0) + setlocal foldexpr=Foldexpr_markdown(v:lnum) + setlocal foldmethod=expr + + " allow the initial foldlevel to be configured in .vimrc + if !exists("g:vim_markdown_initial_foldlevel") + let g:vim_markdown_initial_foldlevel=0 + endif + let &l:foldlevel=g:vim_markdown_initial_foldlevel + + "---------- everything after this is optional ----------------------- + " change the following fold options to your liking + " see ':help fold-options' for more + setlocal foldenable + setlocal foldcolumn=0 + set foldmethod=expr + set foldopen-=search +endif