MPS 2018.2 Help

Live Templates

Live templates can be used to insert frequently-used constructs into your source code, for example, loops, conditions, various declarations, print statements, tags, and so on. To expand a code snippet, type the corresponding template abbreviation and press N/A. Keep pressing N/A to jump from one variable in the template to the next one. Press N/A to move to the previous variable. For more information, see Live Template Variables.

The following types of live templates are distinguished:

  • Simple templates contain only fixed plain text. When you expand a simple template, the text is automatically inserted into your source code, replacing the abbreviation.

    AbbreviationExpands to ...
    public static final String
    public static void main(String[] args){ }
  • Parameterized templates contain variables that enable user input. When you expand a parameterized template, variables are either replaced by input fields for the user to specify manually, or calculated by MPS automatically.

    AbbreviationExpands to ...
    for (int i = 0; i < ; i++) { }
    if (var == null) { }
  • Surround templates wrap a block of selected code with text specified by the user.

    For example, T expands into a pair of tags, for which you can specify a name. You can also select a block of code, then press N/A to open the Select Template popup and select the T template to wrap the selection with a pair of tags.

To configure live templates, open the Settings / Preferences Dialog (N/A), click Editor and then click Live Templates. This dialog lists the available live templates, enables you to edit them and create new ones. Templates are grouped according to the context where they can be used (usually the language that they apply to). To move any template to another group, right-click the template, point to Move, and click the necessary group name.

Each live template is defined by an abbreviation containing alphanumeric characters, dots, and hyphens. The abbreviation must be unique within a group, but the same abbreviation may be used in different groups and expand to different constructs according to the context of the corresponding group. Abbreviations of modified default templates are shown in the list with blue font.

To restore a modified template to the default settings:

Last modified: 29 May 2018