IntelliJ IDEA 11.0 Web Help

IntelliJ IDEA enables the following ways of creating file templates:

Also, you can work with exclude template variables and directives from expanding on applying templates by escaping the $ and # symbols.

To create a file template from scratch
  1. On the main menu, choose File | Settings for Windows and Linux or IntelliJ IDEA | Preferences | for Mac OS. Then click File Templates.
  2. In the File Templates dialog box that opens switch to the Templates tab.
  3. Click the Add button add on the toolbar and specify the template name, the file extension, and the body of the template, which can contain:
    • Plain text.
    • #parse directives to work with template includes.
    • Predefined variables to be expanded into corresponding values in the format ${<variable_name>}.

      The available predefined file template variables are:

      • ${PACKAGE_NAME} - the name of the target package where the new class or interface will be created.
      • ${USER} - login name of the current user.
      • ${NAME} - the name of the file that will be created.
      • ${DATE} - the current system date.
      • ${TIME} - the current system time.
      • ${YEAR} - the current year.
      • ${MONTH} - the current month.
      • ${DAY} - the current day of the month.
      • ${HOUR} - the current hour.
      • ${MINUTE} - the current minute.
    • Custom variables to define their names during the file creation.
  4. To have a variable or directive rendered "as is" upon template expansion, escape the $ or # character in reposition.
  5. Apply the changes and close the dialog box.
To create a file template from an existing one
  1. Open the File Templates dialog box and switch to the Templates tab.
  2. Click the Copy button copy on the toolbar and change the template name, extension, and source code as required.
  3. Apply the changes and close the dialog box.
To create a file template from a file
  1. Open the desired file in the editor.
  2. On the main menu, choose Tools | Save File as Template.
  3. In the File Templates dialog box that opens specify the new template name and edit the source code, if necessary.
  4. Apply the changes and close the dialog box.
To create and reference an include template
  1. In the File Templates dialog box, switch to the Includes tab.
  2. Click the Add button add on the toolbar and specify include template name, extension, and the source code.
  3. In the Templates tab, select the desired template and click the Edit button.
  4. To include a template, insert the #parse directive in the source code.

See Also

Concepts:

Reference:

Web Resources: