neovim

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

rmd.vim (2597B)


      1 " Vim filetype plugin file
      2 " Language:		R Markdown file
      3 " Maintainer:		This runtime file is looking for a new maintainer.
      4 " Former Maintainer:	Jakson Alves de Aquino <jalvesaq@gmail.com>
      5 " Former Repository:	https://github.com/jalvesaq/R-Vim-runtime
      6 " Last Change:
      7 "  2024 Feb 28 by Vim Project
      8 "  2024 Sep 23 by Vim Project: properly restore fex option
      9 " Original work by Alex Zvoleff (adjusted from R help for rmd by Michel Kuhlmann)
     10 
     11 " Only do this when not yet done for this buffer
     12 if exists("b:did_ftplugin")
     13  finish
     14 endif
     15 
     16 if exists('g:rmd_include_html') && g:rmd_include_html
     17  runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
     18 endif
     19 
     20 setlocal comments=fb:*,fb:-,fb:+,n:>
     21 setlocal commentstring=#\ %s
     22 setlocal formatoptions+=tcqln
     23 setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*[-*+]\\s\\+
     24 setlocal iskeyword=@,48-57,_,.
     25 
     26 let s:cpo_save = &cpo
     27 set cpo&vim
     28 
     29 function FormatRmd()
     30  if search("^[ \t]*```[ ]*{r", "bncW") > search("^[ \t]*```$", "bncW")
     31    setlocal comments=:#',:###,:##,:#
     32  else
     33    setlocal comments=fb:*,fb:-,fb:+,n:>
     34  endif
     35  return 1
     36 endfunction
     37 
     38 let s:last_line = 0
     39 function SetRmdCommentStr()
     40  if line('.') == s:last_line
     41    return
     42  endif
     43  let s:last_line = line('.')
     44 
     45  if (search("^[ \t]*```[ ]*{r", "bncW") > search("^[ \t]*```$", "bncW")) || ((search('^---$', 'Wn') || search('^\.\.\.$', 'Wn')) && search('^---$', 'bnW'))
     46    set commentstring=#\ %s
     47  else
     48    set commentstring=<!--\ %s\ -->
     49  endif
     50 endfunction
     51 
     52 " If you do not want both 'comments' and 'commentstring' dynamically defined,
     53 " put in your vimrc: let g:rmd_dynamic_comments = 0
     54 if !exists("g:rmd_dynamic_comments") || (exists("g:rmd_dynamic_comments") && g:rmd_dynamic_comments == 1)
     55  setlocal formatexpr=FormatRmd()
     56  augroup RmdCStr
     57    autocmd!
     58    autocmd CursorMoved <buffer> call SetRmdCommentStr()
     59  augroup END
     60 endif
     61 
     62 " Enables pandoc if it is installed
     63 unlet! b:did_ftplugin
     64 runtime ftplugin/pandoc.vim
     65 
     66 " Don't load another plugin for this buffer
     67 let b:did_ftplugin = 1
     68 
     69 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
     70  let b:browsefilter = "R Source Files (*.R, *.Rnw, *.Rd, *.Rmd, *.Rrst, *.qmd)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst;*.qmd\n"
     71  if has("win32")
     72    let b:browsefilter .= "All Files (*.*)\t*\n"
     73  else
     74    let b:browsefilter .= "All Files (*)\t*\n"
     75  endif
     76 endif
     77 
     78 if exists('b:undo_ftplugin')
     79  let b:undo_ftplugin .= " | setl cms< com< fo< flp< isk< fex< | unlet! b:browsefilter"
     80 else
     81  let b:undo_ftplugin = "setl cms< com< fo< flp< isk< fex< | unlet! b:browsefilter"
     82 endif
     83 
     84 let &cpo = s:cpo_save
     85 unlet s:cpo_save
     86 
     87 " vim: sw=2