0

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

:g/^#

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

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.

| improve this answer | |
0

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.

| improve this answer | |

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.