1" Vim filetype plugin
2" Language:		Markdown
3" Maintainer:		Tim Pope <[email protected]>
4" Last Change:		2016 Aug 29
5
6if exists("b:did_ftplugin")
7  finish
8endif
9
10runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
11
12setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=>\ %s
13setlocal formatoptions+=tcqln formatoptions-=r formatoptions-=o
14setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+\\\|^\\[^\\ze[^\\]]\\+\\]:
15
16if exists('b:undo_ftplugin')
17  let b:undo_ftplugin .= "|setl cms< com< fo< flp<"
18else
19  let b:undo_ftplugin = "setl cms< com< fo< flp<"
20endif
21
22function! MarkdownFold()
23  let line = getline(v:lnum)
24
25  " Regular headers
26  let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=')
27  if depth > 0
28    return ">" . depth
29  endif
30
31  " Setext style headings
32  let nextline = getline(v:lnum + 1)
33  if (line =~ '^.\+$') && (nextline =~ '^=\+$')
34    return ">1"
35  endif
36
37  if (line =~ '^.\+$') && (nextline =~ '^-\+$')
38    return ">2"
39  endif
40
41  return "="
42endfunction
43
44if has("folding") && exists("g:markdown_folding")
45  setlocal foldexpr=MarkdownFold()
46  setlocal foldmethod=expr
47  let b:undo_ftplugin .= " foldexpr< foldmethod<"
48endif
49
50" vim:set sw=2:
51