2014-07-10 21:05:51 -07:00
|
|
|
" Vim filetype plugin
|
2022-10-16 23:19:48 -07:00
|
|
|
" Language: Markdown
|
|
|
|
" Maintainer: Tim Pope <https://github.com/tpope/vim-markdown>
|
2023-12-28 16:29:38 -07:00
|
|
|
" Last Change: 2023 Dec 28
|
2024-06-04 00:39:28 -07:00
|
|
|
" 2024 May 24 by Riley Bruins <ribru17@gmail.com> ('commentstring')
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
if exists("b:did_ftplugin")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
|
|
|
|
|
2022-10-16 23:19:48 -07:00
|
|
|
let s:keepcpo= &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2024-06-04 00:39:28 -07:00
|
|
|
setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=<!--\ %s\ -->
|
2014-07-10 21:05:51 -07:00
|
|
|
setlocal formatoptions+=tcqln formatoptions-=r formatoptions-=o
|
2022-10-16 23:19:48 -07:00
|
|
|
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*[-*+]\\s\\+\\\|^\\[^\\ze[^\\]]\\+\\]:\\&^.\\{4\\}
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
if exists('b:undo_ftplugin')
|
2022-10-16 23:19:48 -07:00
|
|
|
let b:undo_ftplugin .= "|setl cms< com< fo< flp< et< ts< sts< sw<"
|
2014-07-10 21:05:51 -07:00
|
|
|
else
|
2022-10-16 23:19:48 -07:00
|
|
|
let b:undo_ftplugin = "setl cms< com< fo< flp< et< ts< sts< sw<"
|
|
|
|
endif
|
|
|
|
|
|
|
|
if get(g:, 'markdown_recommended_style', 1)
|
|
|
|
setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists("g:no_plugin_maps") && !exists("g:no_markdown_maps")
|
|
|
|
nnoremap <silent><buffer> [[ :<C-U>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "bsW")<CR>
|
|
|
|
nnoremap <silent><buffer> ]] :<C-U>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "sW")<CR>
|
|
|
|
xnoremap <silent><buffer> [[ :<C-U>exe "normal! gv"<Bar>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "bsW")<CR>
|
|
|
|
xnoremap <silent><buffer> ]] :<C-U>exe "normal! gv"<Bar>call search('\%(^#\{1,5\}\s\+\S\\|^\S.*\n^[=-]\+$\)', "sW")<CR>
|
|
|
|
let b:undo_ftplugin .= '|sil! nunmap <buffer> [[|sil! nunmap <buffer> ]]|sil! xunmap <buffer> [[|sil! xunmap <buffer> ]]'
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
|
2020-10-21 22:44:44 -07:00
|
|
|
function! s:NotCodeBlock(lnum) abort
|
2023-12-28 16:29:38 -07:00
|
|
|
return synIDattr(synID(a:lnum, 1, 1), 'name') !=# 'markdownCodeBlock'
|
2020-10-21 22:44:44 -07:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! MarkdownFold() abort
|
2017-04-28 12:06:44 -07:00
|
|
|
let line = getline(v:lnum)
|
|
|
|
|
2020-10-21 22:44:44 -07:00
|
|
|
if line =~# '^#\+ ' && s:NotCodeBlock(v:lnum)
|
|
|
|
return ">" . match(line, ' ')
|
2017-04-28 12:06:44 -07:00
|
|
|
endif
|
|
|
|
|
|
|
|
let nextline = getline(v:lnum + 1)
|
2020-10-21 22:44:44 -07:00
|
|
|
if (line =~ '^.\+$') && (nextline =~ '^=\+$') && s:NotCodeBlock(v:lnum + 1)
|
2017-04-28 12:06:44 -07:00
|
|
|
return ">1"
|
|
|
|
endif
|
|
|
|
|
2020-10-21 22:44:44 -07:00
|
|
|
if (line =~ '^.\+$') && (nextline =~ '^-\+$') && s:NotCodeBlock(v:lnum + 1)
|
2017-04-28 12:06:44 -07:00
|
|
|
return ">2"
|
|
|
|
endif
|
|
|
|
|
|
|
|
return "="
|
|
|
|
endfunction
|
|
|
|
|
2020-10-21 22:44:44 -07:00
|
|
|
function! s:HashIndent(lnum) abort
|
|
|
|
let hash_header = matchstr(getline(a:lnum), '^#\{1,6}')
|
|
|
|
if len(hash_header)
|
|
|
|
return hash_header
|
|
|
|
else
|
|
|
|
let nextline = getline(a:lnum + 1)
|
|
|
|
if nextline =~# '^=\+\s*$'
|
|
|
|
return '#'
|
|
|
|
elseif nextline =~# '^-\+\s*$'
|
|
|
|
return '##'
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! MarkdownFoldText() abort
|
|
|
|
let hash_indent = s:HashIndent(v:foldstart)
|
|
|
|
let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')
|
|
|
|
let foldsize = (v:foldend - v:foldstart + 1)
|
|
|
|
let linecount = '['.foldsize.' lines]'
|
|
|
|
return hash_indent.' '.title.' '.linecount
|
|
|
|
endfunction
|
|
|
|
|
2022-10-16 23:19:48 -07:00
|
|
|
if has("folding") && get(g:, "markdown_folding", 0)
|
2017-04-28 12:06:44 -07:00
|
|
|
setlocal foldexpr=MarkdownFold()
|
|
|
|
setlocal foldmethod=expr
|
2020-10-21 22:44:44 -07:00
|
|
|
setlocal foldtext=MarkdownFoldText()
|
2022-10-16 23:19:48 -07:00
|
|
|
let b:undo_ftplugin .= "|setl foldexpr< foldmethod< foldtext<"
|
2017-04-28 12:06:44 -07:00
|
|
|
endif
|
|
|
|
|
2022-10-16 23:19:48 -07:00
|
|
|
let &cpo = s:keepcpo
|
|
|
|
unlet s:keepcpo
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
" vim:set sw=2:
|