CLion 2022.2 Help

File and Code Templates

Use this page to view, edit, and create file templates.

Scheme

Select the scope to which the file templates apply:

  • Default: configure file templates for the entire application. These templates are available in all projects that you open with the current IDE instance. Use them as your personal templates that you prefer regardless of the specific project. CLion stores global templates in the IDE configuration directory under fileTemplates.

  • Project: configure file templates specific for the current project. These templates are available to everyone who works on this project. CLion stores them in the project folder under .idea/fileTemplates.

Tabs

CLion includes the following types of templates:

Files

CLion uses file templates to create new files.

Includes

These are templates for reusable fragments that can be included in file templates. For more information, see Reusable content in templates.

Code

CLion uses these built-in templates as snippets to generate various constructs.

You can edit the templates available on this tab to modify how CLion generates these constructs, but you cannot create new ones. To create custom code snippets, use live templates.

Toolbar

the Create Template button Create Template

Create a new file or include template.

the Create Child Template File button Create Child Template File

Add a child template to the selected template to create a set of multiple files with one template.

the Remove Template button Remove Template

Delete the selected file or include template. You can delete only custom templates, not the default ones.

the Copy Template button Copy Template

Create a copy of the selected file or include template.

the Revert to Original Template button Revert to Original Template

Revert the selected template to its original state. You can revert only modified default templates.

Template settings

Name

Specify the name of the template to display in the UI.

Not available for default built-in templates.

Extension

Specify the file extension to associate the template with a specific file type.

Not available for default built-in templates.

File name

If necessary, specify a name for the file created from this template. By default, CLion prompts the user to enter a name when adding the file. You can hard code a specific name to avoid the prompt entirely, or compose a template from available variables. For example, here is how you can use the specified name but put it one directory above the one that was selected during file creation: ../${NAME}

Not available for default built-in templates.

Template editor

Edit the code used for the selected template. For information about the syntax used in file templates, see Syntax.

Reformat according to style

Reformat the contents generated based on this template according to the code style defined for this file type.

This option is available only for file templates.

Enable Live Templates

Insert live templates inside the file template. Use the Velocity escape syntax to include live template variables in a file template, for example: #[[ $MY_VARIABLE$ $END$ ]]#

The following variables are available in CMakeLists.txt file templates:

${CMAKE_DEFAULT_PROJECT_FILE}

- the main.cpp/main.c/libary.cpp/library.c file of the project.

${CMAKE_LANGUAGE_VERSION}

- the selected language standard.

${CMAKE_MAJOR_VERSION}

- the major number of the minimum supported CMake version. For example, if the version if 3.20, this variable corresponds to 3.

${CMAKE_MINOR_VERSION}

- the minor number of the minimum supported CMake version. For example, if the version if 3.20, this variable corresponds to 20.

${CMAKE_LIBRARY_TYPE}

-SHARED for shared libraries.

${QT_VERSION}

- the selected Qt version.

${REQUIRED_LIBS}

- the Qt libraries required for the selected project type. By default, they are Core for Qt Console Executable and Core, Gui, Widgets for Qt Widgets Executable.

Last modified: 21 July 2022