diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-23 09:57:55 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-23 09:57:55 +1200 |
commit | 67858c848fe217469bd457c6767f712de43409f5 (patch) | |
tree | 9ff36d50666684582a657e00030ce183d04aef72 | |
parent | Remove redundancies from 'formatoptions' setting (diff) | |
download | dotfiles-67858c848fe217469bd457c6767f712de43409f5.tar.gz dotfiles-67858c848fe217469bd457c6767f712de43409f5.zip |
Adopt heading-based Markdown folding
This is just me adapting Tim Pope's original code a little to fit with
how I normally write Vim script. We'll try this fold method out and see
if it suits.
-rw-r--r-- | vim/ftplugin/markdown.vim | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim index 2bfdebcb..f98f7420 100644 --- a/vim/ftplugin/markdown.vim +++ b/vim/ftplugin/markdown.vim @@ -17,33 +17,31 @@ setlocal formatoptions+=ln let &l:formatlistpat = '^\s*\d\+\.\s\+\|^[-*+]\s\+\|^\[^\ze[^\]]\+\]:' let b:undo_ftplugin .= '|setlocal formatoptions< formatlistpat<' +" Let's try this heading-based fold method out function! MarkdownFold() let line = getline(v:lnum) " Regular headers let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=') if depth > 0 - return ">" . depth + return '>' . depth endif " Setext style headings - let nextline = getline(v:lnum + 1) - if (line =~ '^.\+$') && (nextline =~ '^=\+$') - return ">1" + if line =~ '^.\+$' + let nextline = getline(v:lnum + 1) + if nextline =~ '^=\+$' + return '>1' + elseif nextline =~ '^-\+$' + return '>2' + endif endif - if (line =~ '^.\+$') && (nextline =~ '^-\+$') - return ">2" - endif - - return "=" + return '=' endfunction - -if has("folding") && exists("g:markdown_folding") - setlocal foldexpr=MarkdownFold() - setlocal foldmethod=expr - let b:undo_ftplugin .= " foldexpr< foldmethod<" -endif +setlocal foldexpr=MarkdownFold() +setlocal foldmethod=expr +let b:undo_ftplugin .= '|setlocal foldexpr< foldmethod<' " Spellcheck documents we're actually editing (not just viewing) if &modifiable && !&readonly |