From d80bf38f92fdd2516b1a2d5576c2a8089453d73b Mon Sep 17 00:00:00 2001 From: todesking Date: Tue, 8 Apr 2014 00:58:30 +0900 Subject: [PATCH] Foldmethod: ignore title-like lines in code block --- after/ftplugin/markdown.vim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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) -- 2.39.5