DataGrip 2019.3 Help

Live templates

By using live templates, you can insert frequently-used constructions into your code. For example, statements or definitions of database objects.

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.

    Abbreviation

    Expands to

    tab
    CREATE TABLE new_table ( col INT NOT NULL );
    col
    col int not null
  • 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 DataGrip automatically.

    Abbreviation

    Expands to

    ins
    INSERT INTO ... (...) VALUES (...);
    sel
    SELECT * FROM ...;
    selc
    SELECT count(*) FROM ... alias WHERE alias. ...;
    selw
    SELECT * FROM ... alias WHERE alias. ...;
    upd
    UPDATE ... SET ... = ... WHERE ...;
  • Surround templates wrap a block of the selected code with the text specified by the user.

Postfix code completion is similar to live templates. It transforms the current expression without selecting it. For example, you can type .cfrom after an expression to invoke the corresponding postfix completion and expand the SELECT statement to SELECT <all_column_names_from_table> FROM <table>.

Configure live templates

To configure live templates, open the Editor | Live Templates page of DataGrip settings Ctrl+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.

Set an SQL dialect for a live template

You can select a specific dialect for a live template. For example, if you want the upd template to work only in MySQL and not in Db2.

  1. In Settings Ctrl+Alt+S, navigate to Editor | Live Templates.

  2. Expand the SQL tree.

  3. Right-click the template you want to modify and select Change context.

  4. In the Change Context Type for Selected Templates window, expand the SQL tree node and select the context.

Set an SQL dialect for a live template

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.

Restore a modified template to the default settings

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

Last modified: 6 December 2019