My workflow is to perform data analysis in R markdown files. They are a mix of text and code chunks, pretty much like jupyter notebooks for python. These files can get long with time and I like to open a buffer with a table of content to navigate between the various headers of the document. I was very happy to use the vim-markdown plugin to generate table of contents for markdown files. In this question, I managed to create an auto command to activate vim-markdown for Rmd files. But now that I start using Nvim-R more intensively, I hit vim-markdown issue 263: activating vim-markdown removes syntax highlighting and auto completion of the R code chunks. That issue hasn't been resolved since 2016, so I guess it will be hard to make both plugins work in parallel.

I'm only interested in the table of content functionality, is there another way to display a table of content on a buffer?

My previous hack was to call


To display a list of markdown headers. I sill miss the extra buffer navigation functionality though.

  • B-layer just released a plugin called musecnav for navigating markup—I’m sure contributions adding support for R-markdown would be appreciated! – D. Ben Knoble Jun 23 '20 at 11:34
  • @D.BenKnoble can you please share a link to that "musecnav" plugin? – Paul Rougieux Jun 23 '20 at 12:42
  • 1

You could use vimgrep and the quickfix window.

Define a command, that searches for headers and open a quickfix window:

command T vimgrep '^\#' % | cw

The defines the command T that first greps the current file for all lines starting with a #` and then opens a quickfix window for it.

To execute it, just run :T. Then move to the heading you are interested in and hit <Enter>.

See :h :vimgrep, :h :cw and .

If you want to dive deeper, also have a look at :h lvimgrep, h :lw and :h location-list.


Voom can create a table of content for R markdown files if you associate that file type to pandoc in the vim configuration file:

let voom_ft_modes = {'markdown': 'pandoc', 'rmd': 'pandoc'}

Then you can also add another name for the command:

au BufRead,BufNewFile *.Rmd command! Toc Voom

Calling :Toc in an R markdown file will now display an outline pane in a vim buffer to the left of your screen.

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.