CLion 2016.3 Help

Configuring Code Style

On this page:

Basics and definitions

If certain coding guidelines exist in a company, one has to follow these guidelines when creating source code. CLion helps maintain the required code style.

The code styles are defined at the project level and at the global level.

  • At the Project level, settings are grouped under the Project scheme, which is predefined and is marked in bold font. The Project style scheme applies to the current project only.

    The default scheme cannot be changed! When any modifications are made, CLion automatically creates a copy of the default scheme. If you want to use a different project level scheme, choose the desired scheme and copy its settings to project.

  • At the Global level, settings are grouped under the predefined Default scheme, and any other scheme created by the user. The global settings are used when the user doesn't want to keep code style settings with the project and share them.

Configuring code style for a language

  1. In Settings, click Code Style, and then click the language in question.
  2. Choose the code style scheme to be used as the base for your custom coding style for the selected language.
  3. Browse through the tabs of the selected language page, and configure code style preferences for it.

Copying code style settings from other languages

For most of the supported languages, you can copy code style settings from other languages or frameworks.

  1. In Settings, click Code Style, and then click the language in question.
  2. Click the link Set from in the upper - right corner and select Language option from the list.
  3. In the drop-down list that appears, click the language to copy the code style from:
    /help/img/idea/2016.3/cl_copyCodeStyle.png

Using code style settings from predefined guidelines

For C/C++, you can copy settings from the predefined code styles. Note, that each predefined code style affects only the certain items of base settings and leaves the rest unchanged.

  1. In Settings, click Code Style, and then click the language in question.
  2. Select the link Set from in the upper-right corner and select Predefined style option from the list.
  3. In the drop-down list that appears, select the code style to copy settings from:
    /help/img/idea/2016.3/cl_copyPredefinedStyle.png

Configuring the code style for a project using EditorConfig

Before you start working with EditorConfig, make sure that the EditorConfig plugin is enabled. The plugin is bundled with CLion and is activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.

Make sure that the check box Enable EditorConfig Support is selected in Editor | Code Style.

For more information, see EditorConfig Website.

To configure the code style for a project using EditorConfig:

  1. In the project tree, right-click a directory where you want to create the EditorConfig settings file and select New | File.
  2. In the dialog that opens, enter .editorconfig and click OK.

    CLion creates an EditorConfig settings file and displays a notification in the pop-up window.

    Every time you open a file, the EditorConfig plugin looks for a file named .editorconfig in the directory of the opened file and in every parent directory. A search for .editorconfig files will stop if the root file path is reached or an EditorConfig file with root = true is found. Therefore, if you want to use the IDE settings instead of the EditorConfig settings, clear the Enable EditConfig Support check box in Editor | Code Style that is selected by default.

  3. Start defining your code style settings. Save(Ctrl+S) your file. Every time you modify the .editorconfig file, save the file to apply changes to your project.
    The EditorConfig code style configuration overrides the code style configuration in the IDE settings.

See Also

Last modified: 29 March 2017