From: todesking Date: Mon, 7 Apr 2014 15:58:30 +0000 (+0900) Subject: Foldmethod: ignore title-like lines in code block X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/d80bf38f92fdd2516b1a2d5576c2a8089453d73b?ds=inline Foldmethod: ignore title-like lines in code block --- diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim index adac473..94267ee 100644 --- a/after/ftplugin/markdown.vim +++ b/after/ftplugin/markdown.vim @@ -6,16 +6,24 @@ " " original version from Steve Losh's gist: https://gist.github.com/1038710 +func! s:is_mkdCode(lnum) + return synIDattr(synID(a:lnum, 1, 0), 'name') == 'mkdCode' +endfunc + +func! s:effective_line(lnum) + return s:is_mkdCode(a:lnum) ? '' : getline(a:lnum) +endfunc + func! Foldexpr_markdown(lnum) if (a:lnum == 1) let l0 = '' else - let l0 = getline(a:lnum-1) + let l0 = s:effective_line(a:lnum-1) endif - let l1 = getline(a:lnum) + let l1 = s:effective_line(a:lnum) - let l2 = getline(a:lnum+1) + let l2 = s:effective_line(a:lnum+1) if l2 =~ '^==\+\s*' " next line is underlined (level 1)