LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

clang-format

automatic source code formatter for C-family languages

TLDR

Format file and output to stdout
$ clang-format [file.cpp]
copy
Format file in place
$ clang-format -i [file.cpp]
copy
Format with specific style
$ clang-format --style=[Google] [file.cpp]
copy
Format using project config file
$ clang-format --style=file [file.cpp]
copy
Format code from stdin
$ echo "int main(){}" | clang-format
copy
Generate style config file
$ clang-format --style=[LLVM] --dump-config > [.clang-format]
copy
Format specific lines only
$ clang-format --lines=[10:20] [file.cpp]
copy
Check if file is formatted
$ clang-format --dry-run --Werror [file.cpp]
copy

SYNOPSIS

clang-format [options] [file...]

DESCRIPTION

clang-format is an automatic code formatting tool for C, C++, Java, JavaScript, JSON, Objective-C, Protobuf, and C# source files. It is part of the LLVM/Clang project and formats code according to configurable style rules.The tool ships with several predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU) and supports extensive customization through .clang-format configuration files. When using --style=file, it searches parent directories for the nearest configuration file.clang-format integrates with most major editors and CI/CD pipelines. The --dry-run option with --Werror enables enforcement of formatting standards in automated checks without modifying files.

PARAMETERS

-i

Edit files in place
--style=style
Coding style (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, file)
--dump-config
Dump configuration to stdout
--assume-filename=name
Filename for language detection when reading stdin
--lines=start:end
Format only specified line range
--dry-run
Don't write changes, exit with error if changes needed
--Werror
Treat formatting issues as errors
--fallback-style=style
Style when no .clang-format found
--verbose
Show files being processed

CONFIGURATION

Create .clang-format or _clang-format in project root:

$ BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 100
copy

PREDEFINED STYLES

LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU

EDITOR INTEGRATION

Integrations available for VS Code, CLion, Vim, Emacs, Sublime Text, and most major editors.

INSTALL

sudo apt install clang-format
copy
sudo apk add clang22-extra-tools
copy
brew install clang-format
copy

CAVEATS

Style "file" uses nearest .clang-format in parent directories. Some formatting choices are opinionated and may require configuration adjustments.

SEE ALSO

clang(1), clang-tidy(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid