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.

  • 1
    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, 2020 at 11:34
  • @D.BenKnoble can you please share a link to that "musecnav" plugin? Jun 23, 2020 at 12:42
  • 1
    – D. Ben Knoble
    Jun 23, 2020 at 12:55
  • 1
    @D.BenKnoble I never noticed this comment before. That was nice of you. I'm actually still working on musecnav...I totally rewrote it, in fact, cuz it was a spaghetti mess. Just need to find the time to upload to GH. Sigh...it always comes down to finding the time....
    – B Layer
    Jul 7, 2022 at 2:00

3 Answers 3


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.

Thanks to jalvesaq for suggesting voom and this setup, as visible in the nvim-r documentation.

  • One year later, Voom remains my preferred tool to manage the table of content of all markdown files, including R markdown. The best feature is the possibility to reorder sections of the document from the TOC pane. Jun 28, 2021 at 10:30

There is an effective solution using plugins. You can achieve a TOC, which you can fuzzy search in, using CtrlP and ctrlp-funky.

Start by installing:

Plug 'ctrlpvim/ctrlp.vim'
Plug 'tacahiroy/ctrlp-funky'

Then you can attach CtrlPFunkyMulti to a key combination.

  • Welcome to Vi and Vim! After cutting out the irrelevant bits (your config, your having the same question, and the niceties which we generally omit here), the answer boils down to "install plugin <link>". It would be nice if you edit your answer to remove the bits I indicated and instead flesh out how to use the plugin, possibly with examples. This allows us to judge the answer as it stands, independently of where it links to or any supporting docs. Such links and docs are of course nice, too, but are tertiary.
    – D. Ben Knoble
    Jun 25, 2021 at 18:24
  • Thanks, see changes.
    – lf_araujo
    Jun 25, 2021 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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