diff options
Diffstat (limited to 'vim/autoload/markdown.vim')
-rw-r--r-- | vim/autoload/markdown.vim | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/vim/autoload/markdown.vim b/vim/autoload/markdown.vim index c0818246..0f03961c 100644 --- a/vim/autoload/markdown.vim +++ b/vim/autoload/markdown.vim @@ -1,3 +1,26 @@ +" Let's try this heading-based fold method out (Tim Pope) +function! markdown#Fold() abort + let line = getline(v:lnum) + + " Regular headers + let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=') + if depth > 0 + return '>' . depth + endif + + " Setext style headings + if line =~# '^.\+$' + let nextline = getline(v:lnum + 1) + if nextline =~# '^=\+$' + return '>1' + elseif nextline =~# '^-\+$' + return '>2' + endif + endif + + return '=' +endfunction + " Add an underline under a heading function! markdown#Heading(char) abort @@ -9,10 +32,17 @@ function! markdown#Heading(char) abort " Build underline string by repeating character by the string length of the " heading text + " let underline = repeat(a:char, strlen(heading)) - " Append the heading text to the buffer on a new line after the heading - call append(pos[1], underline) + " If the line after this one looks like it's already an underline, replace + " it; otherwise, create a new underline + " + if getline(pos[1] + 1) =~# '^[-=]\{2,}$' + call setline(pos[1] + 1, underline) + else + call append(pos[1], underline) + endif " Move to the first column of the underline we just inserted let pos[1] += 1 |