# ClangFormat as alternative formatter

> **TL;DR**
> Settings | Editor | Code Style | C/C++
>
>
>
> By default: Disabled
>
>
>
> Bundled `.clang-format` version: see `Settings | Editor | Code Style | C/C++ | Clang-Format`

[ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) is a popular code formatting tool that helps maintain a common code style across team members and IDEs. It provides an option to store formatting settings in special YAML files named  `.clang-format` or `_clang-format`. In CLion, you can use ClangFormat as an alternative to the built-in code formatter.

## .clang-format configuration files

`.clang-format` files with formatting conventions should be placed in the project tree. Each of them applies to code files at the same level and in the subdirectories. Having multiple `.clang-format` files for a single project lets you, if needed, use different styles for different code folders.

ClangFormat offers many [style options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html), which you can mix to create the set of rules most suitable for your team. It also provides several built-in styles for C/C++: [LLVM](http://llvm.org/docs/CodingStandards.html), [Google](https://google.github.io/styleguide/cppguide.html), [WebKit](https://webkit.org/code-style-guidelines/), [Chromium](https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md), and [Mozilla](https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style). These predefined styles can be used as is or as a baseline for your custom set of style definitions.

To generate a `.clang-format` file with, for example, LLVM code style, run the following command (make sure to have [ClangTools](https://clang.llvm.org/docs/ClangTools.html) already [installed](http://releases.llvm.org/download.html)):

```CONSOLE
clang-format -style=llvm -dump-config > .clang-format
```

> **Tip:**
> There is a handy interactive .clang-format builder: [clang-format configurator](https://clang-format-configurator.site).

## ClangFormat in CLion

You can enable or disable ClangFormat using one of the following options:

Procedure:

* To use formatting options from a `.clang-format` file with the built-in CLion formatter, go to `Settings | Editor | Code Style | C/C++ | General | C/C++ formatting engine`, select CLion formatter, and enable the Read code style from .clang-format files checkbox.

![Enable ClangFormat in the code style settings dialog](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_engine.png)

* Alternatively, select the Clang-Format option below.

* While in a `.h`, `.c`, or `.cpp` file, click Enable ClangFormat from the code formatting switcher in the status bar:

![Enable ClangFormat from the code style switcher](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_switcherenable.png)

After you enable ClangFormat, the appropriate formatting will be applied when you:

* Type in the editor (which includes indentation after `Enter` or `Backspace`, auto-completion, code generation, refactorings, and quick-fixes).

* Call Code | Reformat Code (`Ctrl+Alt+L` (Windows), `⌘ ⌥ L` (macOS), `⌘ ⌥ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ L` (macOS System Shortcuts), `Ctrl+Alt+L` (XWin), `Ctrl+Alt+L` (GNOME), `Alt+Shift+L` (KDE), `Ctrl+Alt+L` (Emacs), `Ctrl+Alt+L` (Sublime Text), `⌘ ⌥ L` (Sublime Text (macOS)), `⌘ ⌥ L` (Xcode), `Ctrl+Alt+Enter` (Visual Studio), `⌘ ⌥ ⏎` (Visual Studio (macOS)), `Ctrl+Alt+L` (ReSharper), `⌘ ⌥ L` (ReSharper (macOS)), `Ctrl+;` (QtCreator), `⌘ ;` (QtCreator (macOS)), `Alt+Shift+F` (NetBeans), `Ctrl+Alt+L` (Eclipse), `⌘ ⇧ F` (Eclipse (macOS))) – this action also lets you reformat a selection of code instead of the whole file.

* Commit changes with the Reformat code option enabled (`Ctrl+O` (Windows), `⌃ O` (macOS), `⌃ O` (IntelliJ IDEA Classic (macOS)), `⌃ O` (macOS System Shortcuts), `Ctrl+O` (XWin), `Ctrl+O` (GNOME), `Ctrl+O` (KDE), `Ctrl+O` (Emacs), `Ctrl+O` (Sublime Text), `Ctrl+O` (Sublime Text (macOS)), `⌃ O` (Xcode), `Ctrl+O` (Visual Studio), `Ctrl+O` (Visual Studio (macOS)), `Ctrl+O` (ReSharper), `Ctrl+O` (ReSharper (macOS)), `Ctrl+O` (QtCreator), `Ctrl+O` (QtCreator (macOS)), `Ctrl+O` (NetBeans), `Ctrl+O` (Eclipse), `Ctrl+O` (Eclipse (macOS))): ![Selecting the Reformat code option before commit](https://resources.jetbrains.com/help/img/idea/2026.2/cl_commit_reformat.png)

Procedure: Change the clang-format binary

1. Go to `Settings | Editor | Code Style | C/C++` and open the General  tab.

2. In the Clang-Format section, set the Use external clang-format instead of the bundled one and provide the path:

![Setting a custom clang-format binary](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_custom.png)

Procedure: Review ClangFormat settings for a file

* Open the file in the editor and click Show ClangFormat Options for Edited File  from the toolbar switcher:

![View ClangFormat settings for a file](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_viewsettings.png)

CLion will show the list of settings taken from the corresponding `.clang-format` file:

![ClangFormat settings file](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_settingsfile.png)

This list is currently read-only. To edit the settings, change them right in the `.clang-format` file.

Procedure: Edit .clang-format files

When you save a `.clang-format` file, CLion applies the changes automatically.

1. Open the desired source file in the editor and click Open '.clang-format' for... from the toolbar switcher:

![switch to clang-format file](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_editconfig.png)

2. To help you edit `.clang-format` configs, CLion provides coding assistance by validating the file content against the JSON Schema built specifically for ClangFormat. Coding assistance includes:

* Completion for options and values, with option descriptions shown in the popup: ![code completion in clang-format config files](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_completion.png)

* Checking the option values for consistency with the allowed value set: ![validating option values](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_optionvaluesmatch.png)

* [Quick documentation popup](viewing-inline-documentation.html) (`Ctrl+Q` (Windows), `F1` (macOS), `⌃ J` (IntelliJ IDEA Classic (macOS)), `⌘ I` (macOS System Shortcuts), `Ctrl+Q` (XWin), `Ctrl+Q` (GNOME), `Ctrl+Q` (KDE), `Ctrl+Q` (Emacs), `Ctrl+Q` (Sublime Text), `Ctrl+Q` (Sublime Text (macOS)), `⌘ ⌃ ⇧ /` (Xcode), `Ctrl+K, I` (Visual Studio), `⌘ K, I` (Visual Studio (macOS)), `Ctrl+Q` (ReSharper), `⌃ Q` (ReSharper (macOS)), `Ctrl+Q` (QtCreator), `Ctrl+Q` (QtCreator (macOS)), `Ctrl+Q` (NetBeans), `Alt+Middle-Click` (Eclipse), `⌥ Middle-Click` (Eclipse (macOS))) to help you explore the option details: ![quick doc for clang-format config files](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangformat_quickdoc.png)

Procedure: Export the formatter settings into a .clang-format file

When you need to save or share the settings of the built-in code formatter, you can export them into a `.clang-format` file:

1. Go to `Settings | Editor | Code Style | C/C++`.

2. Click ![](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.settings.svg) next to the Scheme field and select Export | .clang-format File:

![Export formatter settings into .clang-format](https://resources.jetbrains.com/help/img/idea/2026.2/cl_codestyles_export_to_clangformat.png)

3. In the dialog that opens, specify the filename and location. By default, CLion suggests `.clang-format` and the current project root.

