vim-context-commentstring icon indicating copy to clipboard operation
vim-context-commentstring copied to clipboard

Comment yaml block in markdown with different character

Open joelostblom opened this issue 1 year ago • 4 comments

Many markdown implementations allow for a leading yaml configuration block like so:

---
title: "My title"
date: 2023-12-29
---

## Heading

Some markdown text

With the vim commentary plugin, I can setup vim to use html comment strings (<!-- %s --> ) for the markdown file, but I can't figure out how to automatically switch to a leading # when commenting in the yaml code block. I tried this pluging but could not get it to work for this scenario, how do I need to change the settings?

joelostblom avatar Dec 30 '23 17:12 joelostblom

Have you seen the "customization" section of the docs?

suy avatar Dec 30 '23 21:12 suy

Additionally: note that this plugin leverages the syntax highlighting of the file format, as explained in the docs. If the syntax highlighting of the format is not able to match when it's the YAML frontmatter or when it's Markdown, it just won't work. I did a quick test, and with my syntax highlighting (whatever is the default on nvim 0.7.2), it is not supported because that syntax highlighting is oblivious to it.

suy avatar Dec 30 '23 21:12 suy

Thanks for the response @suy! It seems like the regions are detected for me as pandocYAMLHeader (likely via my pandoc plugin)

image

But when I try adding the following

let g:context#commentstring#table.pandoc = { 'pandocYAMLHeader' : '# %s' }

to my vimrc, it does not have an effect on changing the commentstring.

Interestingly, even without vim-context-commentstring installed the yaml commenting is working as I want in files with the extension .qmd (quarto filetype) but not in .md (markdown filetype) files.

joelostblom avatar Dec 30 '23 22:12 joelostblom

I don't know enough of your setup, but I did a quick try with the pandoc syntax, and call extend(g:context#commentstring#table, {'pandoc': {'pandocYAMLHeader': '# %s'}}) to add an extra rule to the table. After I do setfiletype pandoc.markdown, the changes apply, and I can comment out the text with <!-- --> and the frontmatter with #.

I don't remember VimL that much to know if the issue might be in how you extend the g:context#commentstring#table dictionary, or if the issue might be the file type (according to the docs of the plugin I linked, the file type should be pandoc.markdown for when using it "manually", without the other pandoc plugin). This might not be the same for you, I don't know.

I hope this helps.

suy avatar Dec 31 '23 10:12 suy