File and Code Templates
Use this page to view, edit, and create file and code templates.
Different groups of templates are located on different tabs.
When you select a template, its contents and description are displayed in the right-hand part of the page.
Per-project vs default scheme
Item | Description |
---|---|
Scheme | Choose whether file and code template settings pertain to the entire workspace, or the current project:
|
Tabs
Tab | Description |
---|---|
Files | This tab displays the available file templates. You can edit the existing templates, or create new ones. |
Includes | This tab shows the templates for reusable fragments that can be included in file templates. You can edit the existing templates, or create new ones. |
Code | This tab displays built-in snippets — templates for code fragments that CLion can generate in various typical situations, for example, for generating implemented or overridden method bodies. You can edit the existing snippets, but you cannot create new ones. |
Toolbar
Item | Tooltip | Description |
---|---|---|
Create Template | Click this button to create a new template in the currently opened tab. This option is only available in the Files and the Includes tabs. The location of the new template is defined by the Schema list. | |
Remove Template | Click this button to delete the selected template. This option is only available for certain templates in the Files and the Includes tabs. | |
Copy Template | Click this button to create a copy of the selected template. This option is only available in the Files and the Includes tabs. | |
Reset to Default | Click this button to revert the selected template to its original state. This option is only available for the templates that have been modified (such templates are highlighted in blue). | |
N/A | Reset | This link appears in the top-right corner of the page when you start editing a template. Clicking this link resets all unsaved changes to any template in any tab. |
Template settings and contents
Item | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Name | This field appears when a new template is created. Specify the name of the new template. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Extension | In this field, specify the extension. CLion will apply this template when new files of this type are created. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Template text | Edit the template contents. You can use:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Reformat according to style | Select this checkbox, to have CLion reformat generated stub files according to the style defined on the Code Style page. This option is only available in the Files tab. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Enable Live Templates | Select this checkbox to use a live template inside a file template. In doing so, one has to put the live template fragments into Velocity escape syntax. For example: Thus, one can specify the cursor position. Note that it is required to use the live template variables here! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description | This read-only field provides information about the template, its predefined variables, and the way they work. This field is not available in custom templates. |
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 |
${CMAKE_MINOR_VERSION} | - the minor number of the minimum supported CMake version. For example, if the version if |
${CMAKE_LIBRARY_TYPE} | - |
${QT_VERSION} | - the selected Qt version. |
${REQUIRED_LIBS} | - the Qt libraries required for the selected project type. By default, they are |