# IDE Code formatting: Zig formatter is in my way

**URL:** <https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050>\
**Category:** Help\
**Tags:** tools\
**Created:** [November 15, 2025, 9:26am UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050 "2025-11-15T09:26:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefanoD](https://ziggit.dev/user_avatar/ziggit.dev/stefanod/32/2781_2.png) [@StefanoD](https://ziggit.dev/u/StefanoD)\
**Post date:** [November 15, 2025, 9:26am UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/1 "2025-11-15T09:26:58Z")

</div>

Hi,  
there are things which I don’t want to format. I.e., a chess board arrangement:

```zig
pub const Square = enum(u6) {
        a1, b1, c1, d1, e1, f1, g1, h1,
        a2, b2, c2, d2, e2, f2, g2, h2,
        a3, b3, c3, d3, e3, f3, g3, h3,
        a4, b4, c4, d4, e4, f4, g4, h4,
        a5, b5, c5, d5, e5, f5, g5, h5,
        a6, b6, c6, d6, e6, f6, g6, h6,
        a7, b7, c7, d7, e7, f7, g7, h7,
        a8, b8, c8, d8, e8, f8, g8, h8,
};

```

The problem is, that this is turned into following by the Zig formatter:

```zig
pub const Square = enum(u6) {
        a1,
        b1,
        c1,
        d1,
        e1,
        f1,
        g1,
        h1,
        a2,
        b2,
        c2,
        d2,
        e2,
        f2,
        g2,
        h2,
        a3,
        b3,
        c3,
        d3,
        e3,
        f3,
        g3,
        h3,
        a4,
        b4,
        c4,
        d4,
        e4,
        f4,
        g4,
        h4,
        a5,
        b5,
        c5,
        d5,
        e5,
        f5,
        g5,
        h5,
        a6,
        b6,
        c6,
        d6,
        e6,
        f6,
        g6,
        h6,
        a7,
        b7,
        c7,
        d7,
        e7,
        f7,
        g7,
        h7,
        a8,
        b8,
        c8,
        d8,
        e8,
        f8,
        g8,
        h8,
    };

```

How can I prevent this?

---

<div class="post-metadata">

**Author:** ![Zonion](https://ziggit.dev/user_avatar/ziggit.dev/zonion/32/4417_2.png) [@Zonion](https://ziggit.dev/u/Zonion)\
**Post date:** [November 15, 2025, 9:29am UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/2 "2025-11-15T09:29:29Z")

</div>

You can turn off formatter with `// zig fmt: off` and then turning back it on with `// zig fmt: on` like:

```zig
// zig fmt: off
pub const Square = enum(u6) {
        a1, b1, c1, d1, e1, f1, g1, h1,
        a2, b2, c2, d2, e2, f2, g2, h2,
        a3, b3, c3, d3, e3, f3, g3, h3,
        a4, b4, c4, d4, e4, f4, g4, h4,
        a5, b5, c5, d5, e5, f5, g5, h5,
        a6, b6, c6, d6, e6, f6, g6, h6,
        a7, b7, c7, d7, e7, f7, g7, h7,
        a8, b8, c8, d8, e8, f8, g8, h8,
};
// zig fmt: on

```

---

<div class="post-metadata">

**Author:** ![StefanoD](https://ziggit.dev/user_avatar/ziggit.dev/stefanod/32/2781_2.png) [@StefanoD](https://ziggit.dev/u/StefanoD)\
**Post date:** [November 15, 2025, 10:19am UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/3 "2025-11-15T10:19:34Z")

</div>

Thank you, that worked! 😄

---

<div class="post-metadata">

**Author:** ![floooh](https://ziggit.dev/user_avatar/ziggit.dev/floooh/32/2989_2.png) [@floooh](https://ziggit.dev/u/floooh)\
**Post date:** [November 15, 2025, 11:47am UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/4 "2025-11-15T11:47:38Z")

</div>

Apart from `zig fmt: off/on` I would really like the zig formatter being a bit smarter when it comes to table-data, ideally honoring the existing number of columns, and aligning the columns vertically by the delimiter (might be a bit much to ask though - so maybe `zig fmt: off/on` is indeed the better solution.

---

<div class="post-metadata">

**Author:** ![Southporter](https://ziggit.dev/user_avatar/ziggit.dev/southporter/32/2500_2.png) [@Southporter](https://ziggit.dev/u/Southporter)\
**Post date:** [November 15, 2025, 2:31pm UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/5 "2025-11-15T14:31:33Z")

</div>

I’ve noticed that the formatter will preserve some table data, especially in array initialization. In this case it’s an enum which I think the formatter will always try to place each value on separate lines. So some of it depends on the kind of token it is looking at.  
But I agree, having it preserve the number of columns even in the case of Enums would be nice.

---

<div class="post-metadata">

**Author:** ![castholm](https://ziggit.dev/user_avatar/ziggit.dev/castholm/32/1330_2.png) [@castholm](https://ziggit.dev/u/castholm)\
**Post date:** [November 15, 2025, 3:37pm UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/6 "2025-11-15T15:37:30Z")

</div>

> [@floooh](#):
>
> I would really like the zig formatter being a bit smarter when it comes to table-data

Relevant proposal: [zig fmt: embrace alignment · Issue #17145 · ziglang/zig · GitHub](https://github.com/ziglang/zig/issues/17145)

> [@Southporter](#):
>
> I’ve noticed that the formatter will preserve some table data, especially in array initialization.

Currently, only array initializers have special logic for aligning elements like table. All other comma-separated list constructs can only be formatted as a single row/column.

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [November 18, 2025, 11:40am UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/7 "2025-11-18T11:40:05Z")

</div>

```zig
// omg: begin
pub const Square = enum(u6) {
        a1,
        b1,
        c1,
        d1,
        e1,
        f1,
        ...
// omg: end

```

After one close encounter with this behavior I decided that I can format myself. The formatter messes up everything.  
This is the line that every of my zig files starts with.

```zig
// zig fmt: off

```

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [November 18, 2025, 12:15pm UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/8 "2025-11-18T12:15:46Z")

</div>

> [@ericlang](#):
>
> This is the line that every of my zig files starts with.
> 
> ```zig
> // zig fmt: off
> 
> ```

Personally I think you are too focused on what your personal style is, it is your choice, but I would rather have the benefits of using the default formatting for 99.9% of cases, instead of completely opting out of it.

If you don’t use the formatter ever, I would rather configure it to be off instead of use the comment to turn it off.

I also wouldn’t want to work on a code base where everyone follows their own favorite style, not allowing personal style also eliminates a lot of the discussions around formatting style. I think some formatting could be improved, but I can live with some imperfections if it means it becomes something that is automated (and doesn’t have to be bike-shed about all the time).

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [November 18, 2025, 1:17pm UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/9 "2025-11-18T13:17:15Z")

</div>

Why shouldnt we be personal? Even when working with a group on 1 codebase. As long as it is readable… I generally don’t like “everyone and everything the same”.  
I turned off the zig formatter but once or twice it still triggered. That’s why I do this now.

---

<div class="post-metadata">

**Author:** ![sbrow](https://ziggit.dev/user_avatar/ziggit.dev/sbrow/32/4970_2.png) [@sbrow](https://ziggit.dev/u/sbrow)\
**Post date:** [November 18, 2025, 2:05pm UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/10 "2025-11-18T14:05:11Z")

</div>

> [@ericlang](#):
>
> Why shouldnt we be personal?

Because using a formatter gets rid of a ton of unnecessary bikeshedding. This is a lesson I personally learned from `go fmt`. The Zig formattter certainly isn’t perfect, but I think the better solution is to make it better rather than completely ignore it.

But hey, if you want to express yourself in the form of code style, be my guest. It’s just that formattters save a ton of brain cycles: tons of times you don’t have to hit tab, or think about whether or not you need a trailing comma, or whether you should call a class `HttpClient` or `HTTPClient`.

Amd more importantly, during code review, no one has to waste time arguing about small details that have little to do with the code’s functionality or maintainability, they can instead focus on its content.

This counts double for a language that strives to “communicate intent precisely”. You can make the same piece of code look wildly different if you turn off formattters and put your mind to it.

---

<div class="post-metadata">

**Author:** ![sbrow](https://ziggit.dev/user_avatar/ziggit.dev/sbrow/32/4970_2.png) [@sbrow](https://ziggit.dev/u/sbrow)\
**Post date:** [November 18, 2025, 2:07pm UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/11 "2025-11-18T14:07:04Z")

</div>

Also, I very much appreciate that you can turn zig fmt off and on arbitrarily. A lot of formattters only let you turn them off at the line or maybe block level, so that’s a nice touch 🙂

---

<div class="post-metadata">

**Author:** ![dajneem23](https://ziggit.dev/user_avatar/ziggit.dev/dajneem23/32/6670_2.png) [@dajneem23](https://ziggit.dev/u/dajneem23)\
**Post date:** [November 18, 2025, 5:12pm UTC](https://ziggit.dev/t/ide-code-formatting-zig-formatter-is-in-my-way/13050/12 "2025-11-18T17:12:15Z")

</div>

i’m using zls with nvim, that’s pretty cool. wanna take a try ?

 ![Screenshot 2025-11-19 at 00.11.30](https://ziggit.dev/uploads/default/original/2X/8/8533697b807dd13371d66b49712151fd88e9e7be.png)
