# New official Go template formatter for VS Code

**URL:** <https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043>\
**Category:** Announcements\
**Created:** [April 24, 2026, 2:01pm UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043 "2026-04-24T14:01:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [April 24, 2026, 2:01pm UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043/1 "2026-04-24T14:01:01Z")

</div>

See [gotmplfmt - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=GoHugoIO.gotmplfmt)

For those who don’t use VS Code, there’s a standalone CLI avalable at [GitHub - gohugoio/gotmplfmt: Work in progress. · GitHub](https://github.com/gohugoio/gotmplfmt/)

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [April 24, 2026, 2:01pm UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043/2 "2026-04-24T14:01:24Z")

</div>



---

<div class="post-metadata">

**Author:** ![idarek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/idarek/32/26229_2.png) [@idarek](https://discourse.gohugo.io/u/idarek)\
**Post date:** [April 26, 2026, 6:31am UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043/3 "2026-04-26T06:31:26Z")

</div>

Apologies for my ignorance, but would like to highlight two things about it.

Received email about “New official Go template formatter for VS Code” and been excited to see what it is and how this will help me.

Sadly, I struggle to understand from reading notes on Marketplace or GitHub, what it is, what it does and how it can benefit myself and others.

I do not doubt that I am not the only one, looking at number of installs been low.

**The core idea of this extension is great, and I think everybody who working with Hugo in VS Code shall have this extension installed.**

Because I will be not the only one who struggle to understand this, I get the below (using Gemini). Hope this will help and will make this extension much more popular among Hugo’ers.

* * *

**What it is**

`gotmplfmt` is a brand-new, official code formatter built by the core Hugo team specifically for Go templates. It consists of two parts: a command-line tool, and a VS Code extension that connects that tool to your editor.

**The Problem it Solves**

Hugo builds its web pages using Go templates (the `{{ ... }}` tags you write inside your `.html` files). Historically, editing these files in VS Code has been frustrating because standard HTML formatters (like Prettier or VS Code’s built-in formatter) do not understand Go template logic. If you ran a standard formatter, it would often break your layout, misalign your `{{ if }}` and `{{ end }}` statements, or jumble your code.

Previously, the Hugo community had to rely on a third-party plugin called `prettier-plugin-go-template`. However, that tool was abandoned years ago and had several bugs. The Hugo team created `gotmplfmt` to be the official, modern replacement.

**What it does (Before & After)**

When you trigger formatting in VS Code (or save your file), `gotmplfmt` automatically organizes your code, fixing the spacing and indentation for both the HTML tags _and_ the Hugo logic.

_Before formatting:_

```auto
<nav>
<ul>
{{range .Site.Menus.main}}
<li>
<a href="{{.URL}}">{{.Name}}</a>
</li>
{{end}}
</ul>
</nav>

```

_After gotmplfmt runs:_`gotmplfmt`

```auto
<nav>
  <ul>
    {{ range .Site.Menus.main }}
      <li>
        <a href="{{ .URL }}">{{ .Name }}</a>
      </li>
    {{ end }}
  </ul>
</nav>

```

**How this is useful to you when managing Hugo sites**

- **Saves Time:** You no longer have to manually hit the spacebar to line up your nested loops (`{{ range }}`) and conditionals (`{{ if }}`).

- **Fewer Errors:** Properly indented logic makes it significantly easier to spot a missing `{{ end }}` tag, which is one of the most common causes of Hugo build errors.

- **Official Support:** Because it is built by the people who make Hugo, it is designed to seamlessly handle all of Hugo’s built-in functions, shortcodes, and embedded templates without breaking.

**A Quick Note on Setup**

If you decide to use it in VS Code, simply installing the extension is not quite enough. The extension relies on the actual Go program running on your computer.

On macOS with Brew

> **brew install go**

You will first need to ensure you have Go installed on your machine, and then run `go install github.com/gohugoio/gotmplfmt@latest` in your terminal so the VS Code extension has the engine it needs to format your files.

> you may also need to **Configure Path** where it is installed in the extension settings, like: **/Users/USERNAME/go/bin/gotmplfmt**

* * *

Also, after:

Set `gotmplfmt` as your Default Formatter

You need to tell VS Code to prioritise the new Hugo formatter for your HTML files.

1. Open your template file, like `head.html` file in VS Code.

2. Open the Command Palette by pressing **Cmd + Shift + P** on your Mac.

3. Type **Format Document With…** and hit Enter.

4. A dropdown menu will appear. Click on **Configure Default Formatter…** at the bottom of that list.

5. Select **gotmplfmt** from the list of options.

From now on, whenever you right-click and select “ **Format Document** ” (or press `Shift` + `Option` + `F`), it will use the correct Hugo formatter to tidy up your code.

**Magic! 🎉**

* * *

Hope that helps.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [April 26, 2026, 9:55am UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043/4 "2026-04-26T09:55:14Z")

</div>

> [@idarek](#):
>
> From now on, whenever you right-click and select “ **Format Document** ” (or press `Shift` + `Option` + `F`), it will use the correct Hugo formatter to tidy up your code.

I have “format on save” enabled.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [April 26, 2026, 11:30am UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043/5 "2026-04-26T11:30:08Z")

</div>

> [@idarek](#):
>
> You will first need to ensure you have Go installed on your machine

I have added some alternative ways to install this without having to have Go installed:

> **[gotmplfmt/vscode at main · gohugoio/gotmplfmt](https://github.com/gohugoio/gotmplfmt/tree/main/vscode#prerequisites)**
>
> main/vscode

.

---

<div class="post-metadata">

**Author:** ![willduncanphoto](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/willduncanphoto/32/11840_2.png) [@willduncanphoto](https://discourse.gohugo.io/u/willduncanphoto)\
**Post date:** [April 26, 2026, 10:44pm UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043/6 "2026-04-26T22:44:21Z")

</div>

I was also kinda lost when I saw the announcement and had to end up here to understand what I am trying to do.

---

<div class="post-metadata">

**Author:** ![bwintx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bwintx/32/10450_2.png) [@bwintx](https://discourse.gohugo.io/u/bwintx)\
**Post date:** [April 27, 2026, 7:45pm UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043/7 "2026-04-27T19:45:15Z")

</div>

Tried it briefly, but on existing .html files it appears to kill syntax highlighting (_i.e._, everything’s just white text on black, in the case of the theme I’m using). Or am I just doing something wrong?

_ **Edit** : I should note this was before I read the instructions above from @idarek — whereas what I’d done was to open an .html file and, in the bottom bar of VS Code, use the “File Association” pop-up. I’d guess that was my problem, but will wait to see whether others can correct me further._

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [April 27, 2026, 8:10pm UTC](https://discourse.gohugo.io/t/new-official-go-template-formatter-for-vs-code/57043/8 "2026-04-27T20:10:50Z")

</div>


