jalvesaq / R-Vim-runtime

Vim runtime scripts of file types that include R code
GNU General Public License v2.0
24 stars 28 forks source link

support syntax highlighting for other languages in Rmarkdown #20

Closed etheleon closed 7 years ago

etheleon commented 7 years ago

Is it possible to enable syntax highlighting for code chunks besides R language for R markdown files?

I understand knitr currently supports other languages in the Rmd https://yihui.name/knitr/demo/engines/

1 ```{python}
2 print("hello world")
3 ```

the vim-pandoc/vim-pandoc-syntax supports this by via the

:PandocHighlight LANG command

so for python it'll be :PandocHighlight python

jalvesaq commented 7 years ago

The branch https://github.com/jalvesaq/R-Vim-runtime/tree/rmd_engine highlights other languages if the chunk header matches either {lang or {r.*engine="lang". If the engine of all following chunks is defined with opts_chunk$set(engine = 'lang'), then the chunks are not correctly highlighted. By default, only R is highlighted. To include other languages, you have to define the value of g:rmd_syn_langs in your vimrc. Example:

let g:rmd_syn_langs = ["r", "python", "c"]
etheleon commented 7 years ago

hi, so does that mean, i need to add the R-Vim-runtime via my vim package manager? I'm using vundle.

edit: Yes it works!

cd ~/vim/bundle
git clone --branch=rmd_engine git@github.com:jalvesaq/R-Vim-runtime.git

in your .vimrc:

Bundle 'git@github.com:jalvesaq/R-Vim-runtime.git'

then run :PluginInstall

solution taken from: https://github.com/VundleVim/Vundle.vim/issues/592