2

R Markdown in VSCode has several nice features - it's syntax colouring is more efficient, it provides little additions like colour pickers for named or rob/hex colours. It would be cool if the same would be available in Quarto - for *.qmd files. In theory one can change association of *.qmd files so that they are displayed as *.rmd - but this also forces VSCode to render them using standard RMD knitting process, which of course fails to recognise QMD-unique features. Is there a way to apply the visual style of *.rmd files to *.qmd but still retaining their association with Quarto renderer in VSCode?

Tried looking for Quarto or RMD setting to see if they could be partially combined, the JSON settings file does not provide any tweak able options to achieve what I want to see.

szymekD
  • 61
  • 4

1 Answers1

0

I think I might be able to help you, to get the visual style of R Markdown files (.rmd) applied to Quarto files (.qmd) in Visual Studio Code while still retaining Quarto's rendering for *.qmd files, you need to separate the text editing experience from the rendering or build process.

For the syntax highlighting, you can tell Visual Studio Code to treat .qmd files as if they were .rmd. You can do this by modifying the settings.json file to include a file association between .qmd files and the R Markdown language identifier.

To do this:

Press Ctrl + , to open settings (or depend on your current OS)

In the top right corner of the settings tab, click on the {} icon to open the settings.json file.

In the settings.json file, add the following code:

"files.associations": {
    "*.qmd": "rmd"
}

This tells Visual Studio Code to treat .qmd files as if they were .rmd, giving them the same syntax highlighting and other editing features.

For the build process, as of my experience so far there isn't a built-in way to have VS Code recognize .qmd files need to be built with Quarto instead of R Markdown's knitting process. However, you could potentially use a task in VS Code to run the appropriate Quarto command when you build the document.

So to create a task:

Go to the Terminal menu and select Configure Default Build Task...

In the dropdown, select Create tasks.json file from template, then others.

Modify the tasks.json to look something like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Quarto Render",
            "type": "shell",
            "command": "quarto render ${file}",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

This will create a build task that runs the quarto render command on the currently open file. You can then use Ctrl + Shift + B to run this build task.

Be careful because the Quarto command needs to be in your path for this to work. If it isn't, you will need to specify the full path to the Quarto executable in the command field.