CLion 2016.2 Help

Creating Template-based Files

On this page:

Introduction

CLion provides file templates for most of the languages that it supports. This lets you create the files with the initial content appropriate for the file purpose.

Generally, the file name extension for a template-based file is set automatically so you don't need to specify it.

Cresating a new file from a template

To create a new file from a template

  1. Do one of the following:
    • In the Project tool window, select the directory in which you want to create a new file, and then choose File | New on the main menu.
    • Right-click the corresponding directory and select New from the context menu.
    • Press Alt+Insert
  2. Select the desired file type.
    • To create a new C++ class, select New | C++ class. In the dialog that opens:
      1. Specify the name of a class.
      2. From the drop-down list, choose the type of the source and header files for the new class, if you want to change the default type which is defined in the New File Extensions tab of the Code Style C/C++dialog.
      3. Select the Create header only check box if you want to create the header file only.
      4. Select the Add to targets check box to add the created files to the list of the source files for the selected target(s).
      5. Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests you to add the created files.
        cl_newClass
    • To create a new C/C++ source file, select New | C/C++ source file. In the dialog that opens:
      1. Specify the name of a file.
      2. From the drop-down list, select the source file type, if you want to change the default type which is defined in the New File Extensions tab of the Code Style C/C++ dialog.
      3. Select the Create an associated header check box if you want to create the respected header file as well.
      4. Select the Add to targets check box to add the created file to the list of the source files for the selected target(s).
      5. Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests you to add the created file.
        cl_newSourceFile
    • To create a new C/C++ header, select New | C/C++ header file. In the dialog that opens:
      1. Specify the name of a file.
      2. From the drop-down list, select the header file type, if you want to change the default type which is defined in the New File Extensions tab of the Code Style C/C++ dialog.
      3. Select the Add to targets check box to add the created file to the list of the source files for the selected target(s).
      4. Select the desired target from the list. In the below pane, see the CMakeLists.txt variable where CLion suggests you to add the created file.
        cl_newHeaderFile
    In addition, the following file templates are also available:
    • HTML
    • Stylesheet
    • JavaScript
    • XSLT
  3. Click OK. The new file that corresponds to the selected file template will be created under the target location.

See Also

Last modified: 20 July 2016