Yes, you can. This code is taken from here .
Put this in a file ~/.vim/r.vim(if any of these files does not exist, create them)
function! TextEnableCodeSnip(filetype,start,end,textSnipHl) abort
let ft=toupper(a:filetype)
let group='textGroup'.ft
if exists('b:current_syntax')
let s:current_syntax=b:current_syntax
" Remove current syntax definition, as some syntax files (e.g. cpp.vim)
" do nothing if b:current_syntax is defined.
unlet b:current_syntax
endif
execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
try
execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
catch
endtry
if exists('s:current_syntax')
let b:current_syntax=s:current_syntax
else
unlet b:current_syntax
endif
execute 'syntax region textSnip'.ft.'
\ matchgroup='.a:textSnipHl.'
\ start="'.a:start.'" end="'.a:end.'"
\ contains=@'.group
endfunction
Now you can use
:call TextEnableCodeSnip( 'r', '```{r}', '```', 'SpecialComment')
As long as the r.vim syntax file exists.
You can also call this method automatically every time you open the .Rmd file:
autocmd BufNewFile,BufRead *.Rmd :call TextEnableCodeSnip( 'r', '```{r}', '```', 'SpecialComment')
r, , :
:call TextEnableCodeSnip( 'r', '```{r.*}', '```', 'SpecialComment')
.vimrc:
autocmd BufNewFile,BufRead *.Rmd :call TextEnableCodeSnip( 'r', '```{r.*}', '```', 'SpecialComment')
.* . , r.* r, .
```{r whatever you want to put here}`
Some r code here
```