IntelliJ IDEA comes with a set of the predefined Live Templates. You can use them as is, or modify them to suit your needs.

If you want to create a new live template, you can do it from scratch, on the base of the copy of an existing template, or from a fragment of source code.

To modify an existing template
  1. In the IDE settings, open the Live Templates page, and expand the desired template group.
  2. Select template you want to change, and click Edit.
  3. In the Edit Live Template dialog box, change template abbreviation as required.
  4. In the Template Text field, edit the template body which may contain plain text and variables. To change variables in a template, click the Edit Variables button.
  5. In the Options section, specify how the template will be expanded and reformatted.
  6. In the Context section, specify the languages and places of code where the editor should be sensitive to the template abbreviation.
  7. Click OK when ready.
To create a new template from scratch
  1. In the IDE settings, open the Live Templates page, and expand the template group where you want to create a new template.
  2. Click the Add button.
  3. In the Add Live Template dialog box, specify the new template abbreviation.
  4. Type the template body, define variables, template group and options, as described in the template modification procedure.
  5. Click OK when ready.
To create a live template from a text fragment
  1. In the editor, select the text fragment to create a live template from.
  2. On the main menu, choose Tools | Save as Live Template. The Edit Live Template dialog box appears.
  3. In the Abbreviation field, type abbreviation to identify your new live template.
  4. Type the template body, define variables, template group and options, as described in the template modification procedure.
  5. Click OK when ready.
Abbreviation may contain alphanumeric characters, dots, and hyphens, and must be unique within a template group. However, you can use same abbreviation for different templates provided they are in different groups.

See Also

Concepts:

Procedures:

Reference:

Web Resources: