Search code examples
pythonvisual-studio-codejinja2

How can I get VS Code to complete closing braces for Jinja bracket pairs?


I'm new to backend development with Python and Django. I'm watching tutorial videos, and I'm noticing something when they insert a Jinja block.

Every time they insert % within a {}, it adds another % to complete the block. This is what happens when I insert a (, and VS Code automatically adds a ) to complete it. How come it's not doing the same for % within a {}? How can I add this functionality to VS Code so I don't have to add the second % every time to cut down on repetition?


Solution

  • That's probably coming from an extension that you just don't have installed. I see https://github.com/wholroyd/vscode-jinja/blob/master/jinja.configuration.json and https://github.com/samuelcolvin/jinjahtml-vscode/blob/main/language-configuration.json. So try installing wholroyd.jinja or samuelcolvin.jinjahtml (I have no affiliation with those extensions).

    The asker states that they solved their problem by putting the following in their settings.json (which uses the monosans.djlint extension):

    "[html][django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": {
        "editor.defaultFormatter": "monosans.djlint",
    },