rmd.vim 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. " Vim filetype plugin file
  2. " Language: R Markdown file
  3. " Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com>
  4. " Homepage: https://github.com/jalvesaq/R-Vim-runtime
  5. " Last Change: Sun Jul 22, 2018 06:51PM
  6. " Original work by Alex Zvoleff (adjusted from R help for rmd by Michel Kuhlmann)
  7. " Only do this when not yet done for this buffer
  8. if exists("b:did_ftplugin")
  9. finish
  10. endif
  11. if exists('g:rmd_include_html') && g:rmd_include_html
  12. runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
  13. endif
  14. setlocal comments=fb:*,fb:-,fb:+,n:>
  15. setlocal commentstring=#\ %s
  16. setlocal formatoptions+=tcqln
  17. setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*[-*+]\\s\\+
  18. setlocal iskeyword=@,48-57,_,.
  19. let s:cpo_save = &cpo
  20. set cpo&vim
  21. function! FormatRmd()
  22. if search("^[ \t]*```[ ]*{r", "bncW") > search("^[ \t]*```$", "bncW")
  23. setlocal comments=:#',:###,:##,:#
  24. else
  25. setlocal comments=fb:*,fb:-,fb:+,n:>
  26. endif
  27. return 1
  28. endfunction
  29. " If you do not want 'comments' dynamically defined, put in your vimrc:
  30. " let g:rmd_dynamic_comments = 0
  31. if !exists("g:rmd_dynamic_comments") || (exists("g:rmd_dynamic_comments") && g:rmd_dynamic_comments == 1)
  32. setlocal formatexpr=FormatRmd()
  33. endif
  34. " Enables pandoc if it is installed
  35. unlet! b:did_ftplugin
  36. runtime ftplugin/pandoc.vim
  37. " Don't load another plugin for this buffer
  38. let b:did_ftplugin = 1
  39. if has("gui_win32") && !exists("b:browsefilter")
  40. let b:browsefilter = "R Source Files (*.R *.Rnw *.Rd *.Rmd *.Rrst)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst\n" .
  41. \ "All Files (*.*)\t*.*\n"
  42. endif
  43. if exists('b:undo_ftplugin')
  44. let b:undo_ftplugin .= " | setl cms< com< fo< flp< isk< | unlet! b:browsefilter"
  45. else
  46. let b:undo_ftplugin = "setl cms< com< fo< flp< isk< | unlet! b:browsefilter"
  47. endif
  48. let &cpo = s:cpo_save
  49. unlet s:cpo_save
  50. " vim: sw=2