Ronni Dyrholm Chidekel

Nunjucks for Visual Studio Code

Full editor support for Nunjucks templates: syntax highlighting, HTML IntelliSense, Emmet, formatting and snippets, in .njk files and in vscode.dev. On the Visual Studio Marketplace since 2015 with more than 260,000 installs, and on Open VSX. Free and open source under the MIT license.

code --install-extension ronnidc.nunjucks

Or search for Nunjucks by ronnidc in the Extensions view. VSCodium, Cursor, Windsurf and other editors that use Open VSX install it from open-vsx.org.

A Nunjucks template in VS Code with highlighted tags, expressions, filters, front matter and embedded JavaScript
An Eleventy template in VS Code's default Dark Modern theme: front matter, template inheritance, a macro import, tags, filters and a script block, each highlighted as what it is.

What it does

File extensions and settings

.njk, .nunjucks, .nunj and .nj open as Nunjucks. The extension deliberately does not take over .html files, so plain HTML keeps its own comments, IntelliSense and formatter. If your templates are .html files, associate them yourself in settings.json, for the whole workspace or for one folder:

"files.associations": {
  "*.html": "nunjucks",
  "src/_includes/**/*.html": "nunjucks"
}

The extension changes two VS Code defaults so that the features above work without configuration: emmet.includeLanguages gets { "nunjucks": "html" }, and html.format.templating is set to true. Both are ordinary settings you can override. Everything else is inherited from your HTML settings, so editor.formatOnSave under [nunjucks] formats templates on save.

With Eleventy

Nunjucks is the most used template language in Eleventy, and the extension knows the syntax Eleventy adds on top: {% setAsync %}, the paired shortcodes of the Render and Bundle plugins (renderTemplate, css, js and html) with CSS, JavaScript and Markdown highlighted inside them, Eleventy's universal filters such as url and slugify, and snippets for all of it. Other shortcodes and custom tags are highlighted as tags even though the extension cannot know their names.

Known limitations

What comes next

Version 1.0 was a rewrite of the grammar and the editor integration. Version 1.1 adds a small language layer on top: syntax errors from the Nunjucks parser shown inline, go to definition for {% extends %}, {% include %} and {% import %} paths, hover documentation and completion for tags, filters and tests, folding of block pairs, and a setting that names your own paired shortcodes. Follow the issues and the changelog for progress.

Bug reports, feature requests and pull requests are welcome on GitHub.