Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table of content for R markdown files #505

Closed
paulrougieux opened this issue Jun 23, 2020 · 3 comments
Closed

Table of content for R markdown files #505

paulrougieux opened this issue Jun 23, 2020 · 3 comments

Comments

@paulrougieux
Copy link

paulrougieux commented Jun 23, 2020

Thanks for the nice plugin.

Markdown files can get long 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. I created an auto command to activate vim-markdown for Rmd files. 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. It has been an open issue since 2016.

In jcfaria/Vim-R-plugin#186 you wrote:
@jalvesaq

I guess that whatever vim-markdown is doing,
it should do only if &filetype == "markdown" or at least &filetype != "rmd".

In fact the only command I want to use from the vim-markdown plugin is the table of content :Toc functionality. In R markdown files, I would like to disable all functions related to code chunks but keep the :Toc command.

Minimal reproducible example:

minimal_no_markdown_toc.vim

set nocompatible
let &runtimepath  = '~/.vim/bundle/Nvim-R,' . &runtimepath
filetype plugin indent on
syntax enable
let maplocalleader = ";"

minimal_markdown_toc.vim

set nocompatible
let &runtimepath  = '~/.vim/bundle/Nvim-R,' . &runtimepath
let &runtimepath  = '~/.vim/bundle/vim-markdown,' . &runtimepath
filetype plugin indent on
syntax enable
"
let maplocalleader = ";"

" enable vim-markdown for .Rmd files too
" This might conflict with the Nvim-R plugin
augroup filetypedetect_markdown
    au!
    au BufRead,BufNewFile *.Rmd set ft=rmd.markdown
augroup END

minimal.Rmd

    # Test

    ```{r test}
    1+1
    1+1
    ```


    ```{r test2}
    2+1
    ```

Starting vim with vim minimal.Rmd -u minimal_no_markdown_toc.vim I get syntax highlight and autocomplete on R chunks but no table of content for the markdown titles.

Starting vim with vim minimal.Rmd -u minimal_markdown_toc.vim I loose syntax highlight and autocomplete on R chunks but I get a table of content.

I guess it is related to the way vim-markdown detects "fenced code blocs".
Any hint on how I could describe it properly to the vim-markdown authors?

@jalvesaq
Copy link
Owner

I have Voom and I have put in my init.vim (vimrc if you use Vim):

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

Then, I run the command :Voom to get a table of contents in a left window.

Is this a viable solution for you?

@paulrougieux
Copy link
Author

paulrougieux commented Jun 23, 2020

I extracted the TOC functionality from plasticboy/vim-markdown into a small plugin called markdown-toc-toc. I placed the plugin in ~/.vim/pack/plugins/start/markdown-toc-toc and this fixes my issue. I now have both Nvim-R autocompletion and syntax highlight working correctly in R markdown chunks as well as a table of content for the markdown titles.

@paulrougieux
Copy link
Author

Thanks voom is very nice, somehow it doesn't recognise double file types ft=rmd.markdown. So I added this to my .vimrc:

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

In fact I don't need to specify R markdown files as 2 file types rmd.markdown anymore. That was only for the vim-markdown plugin.

I like the fact that Voom can open 2 table of content buffer for 2 files in a split view. Thanks a lot for the advice I prefer Voom to the other solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants