neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

markdown.vim (2960B)


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