1" markdown Text with R statements 2" Language: markdown with R code chunks 3" Homepage: https://github.com/jalvesaq/R-Vim-runtime 4" Last Change: Sat Jan 28, 2017 10:06PM 5" 6" CONFIGURATION: 7" To highlight chunk headers as R code, put in your vimrc (e.g. .config/nvim/init.vim): 8" let rmd_syn_hl_chunk = 1 9" 10" For highlighting pandoc extensions to markdown like citations and TeX and 11" many other advanced features like folding of markdown sections, it is 12" recommended to install the vim-pandoc filetype plugin as well as the 13" vim-pandoc-syntax filetype plugin from https://github.com/vim-pandoc. 14" 15" TODO: 16" - Provide highlighting for rmarkdown parameters in yaml header 17 18if exists("b:current_syntax") 19 finish 20endif 21 22" load all of pandoc info, e.g. from 23" https://github.com/vim-pandoc/vim-pandoc-syntax 24runtime syntax/pandoc.vim 25if exists("b:current_syntax") 26 let rmdIsPandoc = 1 27 unlet b:current_syntax 28else 29 let rmdIsPandoc = 0 30 runtime syntax/markdown.vim 31 if exists("b:current_syntax") 32 unlet b:current_syntax 33 endif 34 35 " load all of the yaml syntax highlighting rules into @yaml 36 syntax include @yaml syntax/yaml.vim 37 if exists("b:current_syntax") 38 unlet b:current_syntax 39 endif 40 41 " highlight yaml block commonly used for front matter 42 syntax region rmdYamlBlock matchgroup=rmdYamlBlockDelim start="^---" matchgroup=rmdYamlBlockDelim end="^---" contains=@yaml keepend fold 43endif 44 45if !exists("g:rmd_syn_langs") 46 let g:rmd_syn_langs = ["r"] 47else 48 let s:hasr = 0 49 for s:lng in g:rmd_syn_langs 50 if s:lng == "r" 51 let s:hasr = 1 52 endif 53 endfor 54 if s:hasr == 0 55 let g:rmd_syn_langs += ["r"] 56 endif 57endif 58 59for s:lng in g:rmd_syn_langs 60 exe 'syntax include @' . toupper(s:lng) . ' syntax/'. s:lng . '.vim' 61 if exists("b:current_syntax") 62 unlet b:current_syntax 63 endif 64 exe 'syntax region rmd' . toupper(s:lng) . 'Chunk start="^[ \t]*``` *{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\).*}$" end="^[ \t]*```$" contains=@' . toupper(s:lng) . ',rmd' . toupper(s:lng) . 'ChunkDelim keepend fold' 65 66 if exists("g:rmd_syn_hl_chunk") && s:lng == "r" 67 " highlight R code inside chunk header 68 syntax match rmdRChunkDelim "^[ \t]*```{r" contained 69 syntax match rmdRChunkDelim "}$" contained 70 else 71 exe 'syntax match rmd' . toupper(s:lng) . 'ChunkDelim "^[ \t]*```{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\).*}$" contained' 72 endif 73 exe 'syntax match rmd' . toupper(s:lng) . 'ChunkDelim "^[ \t]*```$" contained' 74endfor 75 76 77" also match and syntax highlight in-line R code 78syntax region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend 79" I was not able to highlight rmdrInline inside a pandocLaTeXCommand, although 80" highlighting works within pandocLaTeXRegion and yamlFlowString. 81syntax cluster texMathZoneGroup add=rmdrInline 82 83" match slidify special marker 84syntax match rmdSlidifySpecial "\*\*\*" 85 86 87if rmdIsPandoc == 0 88 syn match rmdBlockQuote /^\s*>.*\n\(.*\n\@<!\n\)*/ skipnl 89 " LaTeX 90 syntax include @LaTeX syntax/tex.vim 91 if exists("b:current_syntax") 92 unlet b:current_syntax 93 endif 94 " Inline 95 syntax match rmdLaTeXInlDelim "\$" 96 syntax match rmdLaTeXInlDelim "\\\$" 97 syn region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>" contains=@texMathZoneGroup 98 " Region 99 syntax match rmdLaTeXRegDelim "\$\$" contained 100 syntax match rmdLaTeXRegDelim "\$\$latex$" contained 101 syntax match rmdLaTeXSt "\\[a-zA-Z]\+" 102 syntax region rmdLaTeXRegion start="^\$\$" skip="\\\$" end="\$\$$" contains=@LaTeX,rmdLaTeXRegDelim keepend 103 syntax region rmdLaTeXRegion2 start="^\\\[" end="\\\]" contains=@LaTeX,rmdLaTeXRegDelim keepend 104 hi def link rmdBlockQuote Comment 105 hi def link rmdLaTeXSt Statement 106 hi def link rmdLaTeXInlDelim Special 107 hi def link rmdLaTeXRegDelim Special 108endif 109 110for s:lng in g:rmd_syn_langs 111 exe 'syn sync match rmd' . toupper(s:lng) . 'SyncChunk grouphere rmd' . toupper(s:lng) . 'Chunk /^[ \t]*``` *{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\)/' 112endfor 113 114hi def link rmdYamlBlockDelim Delim 115for s:lng in g:rmd_syn_langs 116 exe 'hi def link rmd' . toupper(s:lng) . 'ChunkDelim Special' 117endfor 118hi def link rmdInlineDelim Special 119hi def link rmdSlidifySpecial Special 120 121let b:current_syntax = "rmd" 122 123" vim: ts=8 sw=2 124