aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-23 09:57:55 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-23 09:57:55 +1200
commit67858c848fe217469bd457c6767f712de43409f5 (patch)
tree9ff36d50666684582a657e00030ce183d04aef72 /vim
parent25a50babaff0b72ea18f14ff35e9a972f27cda0e (diff)
downloaddotfiles-67858c848fe217469bd457c6767f712de43409f5.tar.gz
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.
Diffstat (limited to 'vim')
-rw-r--r--vim/ftplugin/markdown.vim28
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