DataGrip 2025.3 Help

Create a live template with variables and functions

In this tutorial, you will learn how to create and use a simple live template that includes variables and functions.

To showcase how variables and functions work in templates, we will add the following variables to the template text:

  • $animal$: an empty one for the users to type a value

  • $food$: a list of three possible values: "meat", "fish", and "grass"

Create a live template with variables

  1. Press Ctrl+Alt+S to open settings and then select Editor | Live Templates.

  2. Select the SQL group, click the Add button, and select Live Template.

  3. In the Abbreviation field, specify the characters that will be used to expand the template. For example, ins_animals.

  4. In the Template text field, paste the following template:

    type $TypeName$ struct { food string } func (p *$TypeName$) PetFood() { food := "$Food$" println("The $typeName$ eats " + food) }
    insert into animals (animal, food) values ('$animal$', '$food$'$END$);
  5. Click Edit Variables and, in the Edit Template Variables dialog, configure the variables:

    • $animal$ remains untouched meaning we expect users to type a value when they apply this template.

    • $food$: in the Expression field, enter enum("meat","fish","grass"). This function allows selecting one of the predefined values when users apply this template.

  6. Click the link in the bottom left corner to define or change the language context where the template will be applicable:

Live template usage

Use the created template

  1. In the editor, start typing the template abbreviation (ins_animals in our example) and select it from the completion dropdown.

  2. Type a value of the variable and press Tab to jump to the next variable.

  3. Using the keyboard arrows, select one of the values for the variable and press Enter.

17 July 2025