Skip to content

Comment yaml block in markdown with different character #15

Description

@joelostblom

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?

Activity

  1. suy commented on Dec 30, 2023

    @suy
    Owner

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

  2. suy commented on Dec 30, 2023

    @suy
    Owner

    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.

  3. joelostblom commented on Dec 30, 2023

    @joelostblom
    Author

    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.

  4. suy commented on Dec 31, 2023

    @suy
    Owner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions