df4798ba9a9d

Merge.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 23 Jun 2011 13:13:19 -0400
parents dcd072c2fbb6 (diff) 44b04b87c558 (current diff)
children 5dcbe77d7b3a
branches/tags (none)
files

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vim/after/ftplugin/markdown.vim	Thu Jun 23 13:13:19 2011 -0400
@@ -0,0 +1,43 @@
+" folding for Markdown headers, both styles (atx- and setex-)
+" http://daringfireball.net/projects/markdown/syntax#header
+"
+" this code can be placed in file
+"   $HOME/.vim/after/ftplugin/markdown.vim
+
+func! Foldexpr_markdown(lnum)
+    let l1 = getline(a:lnum)
+
+    if l1 =~ '^\s*$'
+        " ignore empty lines
+        return '='
+    endif
+
+    let l2 = getline(a:lnum+1)
+
+    if  l2 =~ '^==\+\s*'
+        " next line is underlined (level 1)
+        return '>1'
+    elseif l2 =~ '^--\+\s*'
+        " next line is underlined (level 2)
+        return '>2'
+    elseif l1 =~ '^#'
+        " current line starts with hashes
+        return '>'.matchend(l1, '^#\+')
+    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