How to use zig fmt with any JetBrains IDE in 2023.


Add a new custom file watcher in your IDE settings and configure it to run zig fmt.

Detailed version

As of today, Zig is at version 0.11.0 and has some support for various editors via its language server zls.

I'm personally using the ZigBrains extension for JetBrains Rider right now (also works in CLion, IntelliJ, etc.), which seems to only support formatting for .zon but not .zig files as of version 0.8.1.

However it may be, you can add file watchers to run zig fmt anyway.

Here's how:

  • Open Settings -> Tools -> File Watchers
  • Add a new <custom> watcher.
  • Set the File Type to ZigLang file.
  • Set Scope to Current file.
  • Set Program to zig
  • Set Arguments to fmt $FileName$
  • Set Working directory to $FileDir$
  • (optional) Disable auto-save ... in the Advanced Options tab.

This will run zig fmt whenever you save a file.

Happy hacking!