robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Barrett Ruthfix(ftplugin): source inherited Lua ftplugins0bb2f5cc08

master
3.0 KiB95 linesraw
1" Vim filetype plugin
2" Language:     Markdown
3" Maintainer:   Tim Pope <https://github.com/tpope/vim-markdown>
4" Last Change:  2023 Dec 28
5"               2024 May 24 by Riley Bruins <ribru17@gmail.com> ('commentstring')
6"               2026 Jun 27 by Vim Project (normalize recommended style guard)
7
8if exists("b:did_ftplugin")
9  finish
10endif
11
12runtime! ftplugin/html[.]{vim,lua} ftplugin/html_*.{vim,lua} ftplugin/html/*.{vim,lua}
13
14let s:keepcpo= &cpo
15set cpo&vim
16
17setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=<!--\ %s\ -->
18setlocal formatoptions+=tcqln formatoptions-=r formatoptions-=o
19setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*[-*+]\\s\\+\\\|^\\[^\\ze[^\\]]\\+\\]:\\&^.\\{4\\}
20
21if exists('b:undo_ftplugin')
22  let b:undo_ftplugin .= "|setl cms< com< fo< flp< et< ts< sts< sw<"
23else
24  let b:undo_ftplugin = "setl cms< com< fo< flp< et< ts< sts< sw<"
25endif
26
27if get(g:, 'markdown_recommended_style',
28      \ get(g:, 'filetype_recommended_style', 1))
29  setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4
30endif
31
32if !exists("g:no_plugin_maps") && !exists("g:no_markdown_maps")
33  nnoremap <silent><buffer> [[ :<C-U>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "bsW")<CR>
34  nnoremap <silent><buffer> ]] :<C-U>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "sW")<CR>
35  xnoremap <silent><buffer> [[ :<C-U>exe "normal! gv"<Bar>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "bsW")<CR>
36  xnoremap <silent><buffer> ]] :<C-U>exe "normal! gv"<Bar>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "sW")<CR>
37  let b:undo_ftplugin .= '|sil! nunmap <buffer> [[|sil! nunmap <buffer> ]]|sil! xunmap <buffer> [[|sil! xunmap <buffer> ]]'
38endif
39
40function! s:NotCodeBlock(lnum) abort
41  return synIDattr(synID(a:lnum, 1, 1), 'name') !=# 'markdownCodeBlock'
42endfunction
43
44function! MarkdownFold() abort
45  let line = getline(v:lnum)
46
47  if line =~# '^#\+ ' && s:NotCodeBlock(v:lnum)
48    return ">" . match(line, ' ')
49  endif
50
51  let nextline = getline(v:lnum + 1)
52  if (line =~ '^.\+$') && (nextline =~ '^=\+$') && s:NotCodeBlock(v:lnum + 1)
53    return ">1"
54  endif
55
56  if (line =~ '^.\+$') && (nextline =~ '^-\+$') && s:NotCodeBlock(v:lnum + 1)
57    return ">2"
58  endif
59
60  return "="
61endfunction
62
63function! s:HashIndent(lnum) abort
64  let hash_header = matchstr(getline(a:lnum), '^#\{1,6}')
65  if len(hash_header)
66    return hash_header
67  else
68    let nextline = getline(a:lnum + 1)
69    if nextline =~# '^=\+\s*$'
70      return '#'
71    elseif nextline =~# '^-\+\s*$'
72      return '##'
73    endif
74  endif
75endfunction
76
77function! MarkdownFoldText() abort
78  let hash_indent = s:HashIndent(v:foldstart)
79  let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')
80  let foldsize = (v:foldend - v:foldstart + 1)
81  let linecount = '['.foldsize.' lines]'
82  return hash_indent.' '.title.' '.linecount
83endfunction
84
85if has("folding") && get(g:, "markdown_folding", 0)
86  setlocal foldexpr=MarkdownFold()
87  setlocal foldmethod=expr
88  setlocal foldtext=MarkdownFoldText()
89  let b:undo_ftplugin .= "|setl foldexpr< foldmethod< foldtext<"
90endif
91
92let &cpo = s:keepcpo
93unlet s:keepcpo
94
95" vim:set sw=2: