When editing long markdown documents it is really good to be able to navigate in them with the :Toc option from vim-markdown.

I also edit long .Rmd documents from vim (when the content is more about text than about R code). I have added the following to my ~/.vimrc:

let g:vim_markdown_auto_extension_ext = 'Rmd'                                                  

:Toc works fine in .md documents, but when I enter :Toc in a .Rmd document, I get the error: "E492: Not an editor command: Toc".

1 Answer 1


The vim-markdown documentation isn't really very clear about g:vim_markdown_auto_extension_ext, but that's actually about the extension it will add to URLs it builds from links in your markdown. It will default to .md, but you can override it here.

By default, it will only recognize a few extensions such as *.md, *.markdown and a few others as being of type "markdown".

In order to accept *.Rmd as a markdown, you should add your own autocmd for it.

You can either create a new file under ~/.vim/ftdetect, such as ~/.vim/ftdetect/Rmd.vim with the line:

au BufRead,BufNewFile *.Rmd set ft=markdown

Or you can add a new augroup block to your vimrc instead:

 augroup filetypedetect_markdown
   au BufRead,BufNewFile *.Rmd set ft=markdown
augroup END
  • I don't know R markdown, but R.markdown may be more appropriate
    – D. Ben Knoble
    Apr 25, 2020 at 1:59
  • @D.BenKnoble thanks I'm now setting 2 file types as you suggested with ft=rmd.markdown. It makes it possible to use 2 plugins which expect different file types (1) vim-markdown gives a table of content for files of type markdown and (2) Nvim-R sends code chunks to R with <localleader>cc for files of type rmd. Jun 22, 2020 at 15:20
  • @PaulRougieux nice, i’ve used similar approaches before. Very convenient
    – D. Ben Knoble
    Jun 22, 2020 at 16:00
  • 1
    It works partly but it's not perfect because "vim-markdown" messes up the syntax highlight and autocomplete of 'Nvim-R". It's been reported in issue 263 Jun 23, 2020 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.