rmd.vim 2.5 KB

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