VS Code extension for cmakefmt — a fast, correct CMake formatter written in Rust.
- Format document — trigger manually via the Command Palette
(
Format Document) or your keyboard shortcut - Format on save — opt in via VS Code's standard
editor.formatOnSavesetting (see below) - Config discovery —
cmakefmtautomatically finds the nearest.cmakefmt.yaml,.cmakefmt.yml, or.cmakefmt.tomlby walking up the directory tree — no configuration needed in VS Code settings - Configurable binary path — point the extension at any
cmakefmtinstallation - Extra arguments — pass additional flags such as
--config-file
Click Install on this page, or search for cmakefmt in the
Extensions view (Ctrl+Shift+X / Cmd+Shift+X).
The extension requires the cmakefmt binary. Install it using one of
these methods:
| Method | Command |
|---|---|
| Homebrew (macOS) | brew install cmakefmt/cmakefmt/cmakefmt |
| pip (any platform) | pip install cmakefmt |
| Cargo (any platform) | cargo install cmakefmt-rust |
| Pre-built binaries | Download from GitHub Releases |
Verify the installation:
cmakefmt --versionOpen any CMakeLists.txt or .cmake file, then open the Command
Palette (Ctrl+Shift+P / Cmd+Shift+P) and run Format Document.
To format on save, enable VS Code's built-in editor.formatOnSave
(see Format on save below).
| Setting | Default | Description |
|---|---|---|
cmakefmt.executablePath |
"cmakefmt" |
Path to the cmakefmt binary. Only needed if cmakefmt is not on your PATH. |
cmakefmt.extraArgs |
[] |
Extra arguments passed to cmakefmt (e.g. ["--config-file", "/path/to/.cmakefmt.yaml"]). |
Tip: You usually don't need
extraArgs.cmakefmtdiscovers your project config automatically from the file being formatted. Only use--config-fileif you need to override the default discovery.
Format-on-save uses VS Code's built-in editor.formatOnSave setting.
Enable it globally, or scope it to CMake files:
To disable it for CMake files only without touching the global setting,
set editor.formatOnSave to false in the [cmake] scope.
If cmakefmt is not on your PATH, set the full path:
// .vscode/settings.json
{
"cmakefmt.executablePath": "/usr/local/bin/cmakefmt"
}"cmakefmt not found" — make sure cmakefmt is installed and on your
PATH. Run cmakefmt --version in the VS Code integrated terminal to
verify. If it works in your regular terminal but not in VS Code, set the
full path in cmakefmt.executablePath.
Formatting does nothing — the file may have a syntax error that
prevents formatting, or there is no .cmakefmt.yaml and the defaults
already match your code. Check for error notifications in the bottom-right
corner of VS Code after saving.
Wrong config is used — run cmakefmt config path <file> in a terminal
to see which config file cmakefmt discovers for a given file.
MIT OR Apache-2.0 — see LICENSE.