PhpStorm 2018.2 Help

Creating Live Templates

The following example procedure illustrates how to create a template for a TODO comment with the current date and user name:

  1. Press Ctrl+Alt+S to open the Settings/Preferences dialog and then go to Editor | Live Templates.
  2. Select the template group where you want to create the new live template (for example, other).
  3. Click Add icons general add svg on the toolbar. A new template item is added and selected.
  4. Specify the following values:

    Text boxDescriptionExample value
    AbbreviationSpecify the characters to expand the templatetodo
    DescriptionSpecify an optional description to identify what the template is forInsert TODO comment with the current date and user name
    Template textSpecify the body of the template with variables//TODO $DATE$ $USER$: $END$
  5. Click Define at the bottom to select the applicable contexts (for example, if it should apply to source files).
  6. Click Edit Variables and select the date() function for $DATE$ and user() for $USER$. Also select Skip if defined for both variables and click OK.

  7. Click OK to apply changes.

Depending on the current system date and user name, the newly created todo template will expand to a line which is similar to the following:

//TODO 15/02/2018 jsmith:

If you want to reuse the same template in multiple groups, or you want to create a new template based on another one, you can duplicate an existing template.

To copy an existing template

  1. Press Ctrl+Alt+S to open the Settings/Preferences dialog and then go to Editor | Live Templates.
  2. Select the template which you want to copy.
  3. Click Duplicate (The Duplicate button) on the toolbar. A new template item is added to the same group as the original, and is selected.
  4. Specify a new abbreviation for the template, an optional description (to identify what the template is for), and modify the template body if necessary. If the template has variables defined, click Edit Variables to configure the variables.
  5. Click OK to apply changes.

To create a new template from a fragment of code

  1. In the editor, select the text fragment to create a live template from.
  2. Select Tools | Save as Live Template from the menu. The Save as Live Template dialog opens, with the new template created and selected.
  3. Specify an abbreviation for the template, an optional description (to identify what the template is for), and modify the template body. If the template has variables defined, click Edit Variables to configure the variables.
  4. Click OK to apply changes and save the template.
Last modified: 21 September 2018