My vim configuration
git clone https://github.com/m-col/vim-misc
Files | Refs | Readme

-rw-r--r-- start/self/after/ftplugin/markdown.vim


      1 " Identify HTML comment-like blocks as markdown comments
      2 setlocal comments+=s:<!---,e:-->
      3 " couldn't get this to work, so just sticking in <br> where needed
      4 "setlocal comments+=s:![**,e:](
      5 
      6 " Folding logic below is derived from the vim-markdown-folding plugin
      7 function! StackedMarkdownFolds()
      8   let thisline = getline(v:lnum)
      9   let prevline = getline(v:lnum - 1)
     10   let nextline = getline(v:lnum + 1)
     11   if thisline =~ '^```.*$' && prevline =~ '^\s*$'  " start of a fenced block
     12     return ">2"
     13   elseif thisline =~ '^```$' && nextline =~ '^\s*$'  " end of a fenced block
     14     return "<2"
     15   endif
     16 
     17   if HeadingDepth(v:lnum) > 0
     18     return ">1"
     19   else
     20     return "="
     21   endif
     22 endfunction
     23 
     24 function! HeadingDepth(lnum)
     25   let level=0
     26   let thisline = getline(a:lnum)
     27   if thisline =~ '^#\+\s\+'
     28     let hashCount = len(matchstr(thisline, '^#\{1,6}'))
     29     if hashCount > 0
     30       let level = hashCount
     31     endif
     32   else
     33     if thisline != ''
     34       let nextline = getline(a:lnum + 1)
     35       if nextline =~ '^=\+\s*$'
     36         let level = 1
     37       elseif nextline =~ '^-\+\s*$'
     38         let level = 2
     39       endif
     40     endif
     41   endif
     42   if level > 0 && HasSyntaxGroup(a:lnum, '\vmarkdown(Code|Highlight)')
     43     " Ignore # or === if they appear within fenced code blocks
     44     let level = 0
     45   endif
     46   return level
     47 endfunction
     48 
     49 function! HasSyntaxGroup(lnum, targetGroup)
     50   let syntaxGroup = map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
     51   for value in syntaxGroup
     52     if value =~ a:targetGroup
     53         return 1
     54     endif
     55   endfor
     56 endfunction
     57 
     58 function! s:FoldText()
     59   let level = HeadingDepth(v:foldstart)
     60   let indent = repeat('#', level)
     61   let title = substitute(getline(v:foldstart), '^#\+\s\+', '', '')
     62 
     63   let spaces_1 = repeat(' ', level) . '   '
     64   let spaces_2 = repeat(' ', 200)
     65 
     66   return indent.spaces_1.title.spaces_2
     67 endfunction
     68 
     69 setlocal foldmethod=expr
     70 
     71 let &l:foldtext = expand('<SID>') . 'FoldText()'
     72 let &l:foldexpr = 'StackedMarkdownFolds()'
     73 
     74 if !exists("b:undo_ftplugin") | let b:undo_ftplugin = '' | endif
     75 let b:undo_ftplugin .= '
     76   \ | setlocal foldmethod< foldtext< foldexpr<
     77   \ '
     78