Intellij Idea Cheat Sheet

Posted : admin On 1/2/2022

Use live templates to insert common constructs into your code, such as loops, conditions, various declarations, or print statements.

IntelliJ IDEA by Hamlet D’Arcy.pdf Related. – here are all the keybindings you must know about IntelliJ Here are some shortcuts I picked from Vlad Rentea’s refactoring kata ALT + j / Successively press ⌃G – to get multi cur.

To expand a code snippet, type the corresponding template abbreviation and press Tab. Keep pressing Tab to jump from one variable in the template to the next one. Press Shift+Tab to move to the previous variable.


Types of live templates

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
    main or psvm
    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 IntelliJ IDEA automatically.

    AbbreviationExpands to
    if (var null) { }
  • Surround templates wrap a block of the selected code with the 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 Ctrl+Alt+J to open the Select Template popup and select the T template to wrap the selection with a pair of tags.

Intellij Idea Ide

Postfix code completion is similar to live templates. It transforms the current expression without selecting it. For example, you can type .if after an expression to invoke the corresponding postfix completion and wrap the expression with an if statement.

Configure live templates

To configure live templates, open the Editor Live Templates page of the Settings/PreferencesCtrl+Alt+S. On the Live Templates page, you can see all the available live templates, edit them and create new templates.

Templates are grouped according to the context where they can be used (usually, by the corresponding language). To move a template to another group, right-click the template, select Move, and then select the necessary group name.

If you set a dialect for a live template, this live template will work only in this dialect.

Intellij Idea Cheat Sheet Mac

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.

Intellij Idea Cheat Sheet

Restore a modified template to the default settings

Intellij Idea Hotkeys Cheat Sheet

  • On the Live Templates page of the Settings/Preferences dialog, right-click the template which you want to restore and click Restore defaults.