My dotfiles. Period.

mkd.vim 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. " folding for Markdown headers, both styles (atx- and setex-)
  2. " http://daringfireball.net/projects/markdown/syntax#header
  3. "
  4. " this code can be placed in file
  5. " $HOME/.vim/after/ftplugin/markdown.vim
  6. "
  7. " original version from Steve Losh's gist: https://gist.github.com/1038710
  8. func! Foldexpr_markdown(lnum)
  9. if (a:lnum == 1)
  10. let l0 = ''
  11. else
  12. let l0 = getline(a:lnum-1)
  13. endif
  14. let l1 = getline(a:lnum)
  15. let l2 = getline(a:lnum+1)
  16. if l2 =~ '^==\+\s*'
  17. " next line is underlined (level 1)
  18. return '>1'
  19. elseif l2 =~ '^--\+\s*'
  20. " next line is underlined (level 2)
  21. return '>2'
  22. elseif l1 =~ '^#'
  23. " don't include the section title in the fold
  24. return '-1'
  25. elseif l0 =~ '^#'
  26. " current line starts with hashes
  27. return '>'.matchend(l0, '^#\+')
  28. else
  29. " keep previous foldlevel
  30. return '='
  31. endif
  32. endfunc
  33. if !exists("g:vim_markdown_folding_disabled")
  34. setlocal foldexpr=Foldexpr_markdown(v:lnum)
  35. setlocal foldmethod=expr
  36. "---------- everything after this is optional -----------------------
  37. " change the following fold options to your liking
  38. " see ':help fold-options' for more
  39. setlocal foldenable
  40. setlocal foldlevel=0
  41. setlocal foldcolumn=0
  42. set foldmethod=expr
  43. set foldopen-=search
  44. endif