rmd.vim 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. " Only do this when not yet done for this buffer
  11. if exists("b:did_ftplugin")
  12. finish
  13. endif
  14. if exists('g:rmd_include_html') && g:rmd_include_html
  15. runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
  16. endif
  17. setlocal comments=fb:*,fb:-,fb:+,n:>
  18. setlocal commentstring=#\ %s
  19. setlocal formatoptions+=tcqln
  20. setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*[-*+]\\s\\+
  21. setlocal iskeyword=@,48-57,_,.
  22. let s:cpo_save = &cpo
  23. set cpo&vim
  24. function FormatRmd()
  25. if search("^[ \t]*```[ ]*{r", "bncW") > search("^[ \t]*```$", "bncW")
  26. setlocal comments=:#',:###,:##,:#
  27. else
  28. setlocal comments=fb:*,fb:-,fb:+,n:>
  29. endif
  30. return 1
  31. endfunction
  32. let s:last_line = 0
  33. function SetRmdCommentStr()
  34. if line('.') == s:last_line
  35. return
  36. endif
  37. let s:last_line = line('.')
  38. if (search("^[ \t]*```[ ]*{r", "bncW") > search("^[ \t]*```$", "bncW")) || ((search('^---$', 'Wn') || search('^\.\.\.$', 'Wn')) && search('^---$', 'bnW'))
  39. set commentstring=#\ %s
  40. else
  41. set commentstring=<!--\ %s\ -->
  42. endif
  43. endfunction
  44. " If you do not want both 'comments' and 'commentstring' dynamically defined,
  45. " put in your vimrc: let g:rmd_dynamic_comments = 0
  46. if !exists("g:rmd_dynamic_comments") || (exists("g:rmd_dynamic_comments") && g:rmd_dynamic_comments == 1)
  47. setlocal formatexpr=FormatRmd()
  48. augroup RmdCStr
  49. autocmd!
  50. autocmd CursorMoved <buffer> call SetRmdCommentStr()
  51. augroup END
  52. endif
  53. " Enables pandoc if it is installed
  54. unlet! b:did_ftplugin
  55. runtime ftplugin/pandoc.vim
  56. " Don't load another plugin for this buffer
  57. let b:did_ftplugin = 1
  58. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  59. let b:browsefilter = "R Source Files (*.R, *.Rnw, *.Rd, *.Rmd, *.Rrst, *.qmd)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst;*.qmd\n"
  60. if has("win32")
  61. let b:browsefilter .= "All Files (*.*)\t*\n"
  62. else
  63. let b:browsefilter .= "All Files (*)\t*\n"
  64. endif
  65. endif
  66. if exists('b:undo_ftplugin')
  67. let b:undo_ftplugin .= " | setl cms< com< fo< flp< isk< fex< | unlet! b:browsefilter"
  68. else
  69. let b:undo_ftplugin = "setl cms< com< fo< flp< isk< fex< | unlet! b:browsefilter"
  70. endif
  71. let &cpo = s:cpo_save
  72. unlet s:cpo_save
  73. " vim: sw=2