Vix.cpp v2.6.0 is here Read the blog
Skip to content

vix fmt

vix fmt formats C++ source files using clang-format.

Use it when you want consistent formatting across your project.

Usage

bash
vix fmt [options] [files...]
1

What it does

vix fmt scans C++ files and formats them with clang-format.

It can format:

txt
one file
multiple files
one directory
multiple directories
the default project folders
1
2
3
4
5

It can also check formatting without modifying files.

Requirements

vix fmt requires clang-format.

If clang-format is not installed, Vix stops with an error:

txt
clang-format not found
Install clang-format to use 'vix fmt'
1
2

Install clang-format before using this command.

Basic usage

bash
# Format the default project folders
vix fmt

# Format specific folders
vix fmt src include

# Format one file
vix fmt main.cpp

# Check whether a file is formatted
vix fmt main.cpp --check

# Ignore paths
vix fmt src --ignore=build --ignore=vendor
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Default behavior

If no files or directories are provided, vix fmt scans:

txt
src/
include/
1
2

A normal project can usually be formatted with:

bash
vix fmt
1

If neither src/ nor include/ contains C++ files, Vix prints:

txt
No C++ files found
1

and exits successfully.

Supported file extensions

vix fmt formats these file types:

txt
.cpp
.hpp
.h
.cc
.cxx
.hh
.hxx
1
2
3
4
5
6
7

Other files are ignored.

Format specific directories

bash
vix fmt src
vix fmt include
vix fmt src include
1
2
3

When a directory is passed, Vix scans it recursively.

Example:

bash
vix fmt src include
1

This formats C++ files inside both directories.

Format specific files

bash
vix fmt main.cpp
vix fmt src/main.cpp include/app.hpp
1
2

Only valid C++ files are formatted.

If a provided file does not exist or is not a supported C++ file, it is ignored.

Check mode

Use --check when you only want to verify formatting:

bash
vix fmt --check
vix fmt src include --check
vix fmt main.cpp --check
1
2
3

In check mode, Vix runs:

bash
clang-format --dry-run --Werror <file>
1

It does not modify files.

If all files are formatted, Vix prints:

txt
All files are properly formatted
1

If some files need formatting, Vix prints the file paths and exits with code 1.

Format mode

Without --check, Vix formats files in place.

It runs:

bash
clang-format -i <file>
1

Example:

bash
vix fmt src include
1

Vix prints each formatted file unless --quiet is enabled.

Ignore paths

Use --ignore to skip a file, directory, or path pattern.

bash
vix fmt src include --ignore=build
vix fmt src include --ignore=build --ignore=vendor
vix fmt src include --ignore .vix
1
2
3

--ignore is repeatable.

Common ignored folders:

txt
build
build-ninja
build-release
vendor
third_party
.vix
dist
node_modules
1
2
3
4
5
6
7
8

Ignore matching is path-based. If the path contains the ignored value, it is skipped.

Example:

bash
vix fmt . --ignore=build
1

This skips paths such as:

txt
build/main.cpp
build-ninja/generated.cpp
1
2

Quiet mode

Use -q or --quiet to suppress non-essential output:

bash
vix fmt --quiet
vix fmt src include --quiet
vix fmt --check --quiet
1
2
3

Quiet mode is useful in scripts where only the exit code matters.

Project formatting file

If a .clang-format file exists, clang-format uses it automatically.

vix fmt does not replace your formatting rules. It delegates formatting to clang-format.

Recommended project root:

txt
.clang-format
src/
include/
1
2
3

Options

OptionDescription
--checkCheck whether files are formatted without modifying them.
--ignore <path>Ignore a file or path pattern. Repeatable.
--ignore=<path>Same as --ignore <path>.
-q, --quietSuppress non-essential output.
-h, --helpShow command help.

Common workflows

Format the current project

bash
vix fmt
1

Check formatting before commit

bash
vix fmt --check
1

Format source and headers

bash
vix fmt src include
1

Format one file

bash
vix fmt src/main.cpp
1

Format generated files after vix make

bash
vix make class User --in src/domain --namespace app::domain
vix fmt src/domain
1
2

Format while ignoring build outputs

bash
vix fmt . \
  --ignore=build \
  --ignore=build-ninja \
  --ignore=.vix \
  --ignore=vendor
1
2
3
4
5

Quiet CI check

bash
vix fmt --check --quiet
1

CI usage

In CI, use check mode:

bash
vix fmt --check
vix check --tests
1
2

This prevents CI from modifying files.

A stricter CI workflow:

bash
vix fmt --check
vix build --preset release
vix tests --preset release
1
2
3
json
{
  "tasks": {
    "fmt": "vix fmt",
    "fmt:check": "vix fmt --check"
  }
}
1
2
3
4
5
6

Then run:

bash
vix task fmt
vix task fmt:check
1
2

Exit behavior

SituationExit code
All files formatted successfully0
No C++ files found0
Check mode passes0
Check mode finds unformatted files1
clang-format is missing1
Formatting fails on at least one file1
Invalid option1

Common mistakes

Forgetting --check in CI

This modifies files:

bash
vix fmt
1

In CI, prefer:

bash
vix fmt --check
1

Formatting generated or vendor files

Use ignore rules:

bash
vix fmt . \
  --ignore=vendor \
  --ignore=third_party \
  --ignore=build \
  --ignore=.vix
1
2
3
4
5

Expecting vix fmt to format every language

vix fmt formats C++ files only.

Supported extensions:

txt
.cpp
.hpp
.h
.cc
.cxx
.hh
.hxx
1
2
3
4
5
6
7

Running without clang-format

Install clang-format first.

Linux example:

bash
sudo apt install clang-format
1

macOS example:

bash
brew install clang-format
1

Expecting Vix to define formatting rules

vix fmt runs clang-format.

Your formatting style should live in:

txt
.clang-format
1
CommandPurpose
vix makeGenerate C++ files.
vix checkValidate build, tests, runtime, and sanitizers.
vix testsRun tests.
vix taskRun reusable project tasks.
vix buildCompile the project.
vix cleanRemove local project cache directories.

Next step

Continue with project cleanup.

Open the vix clean guide

Released under the MIT License.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.