IDE and terminal snippets
What is JetBrains Live Templates? An introduction to JetBrains' code snippet feature in IntelliJ IDEA
JetBrains Live Templates is a feature of IntelliJ IDEA that inserts common code constructs, such as loops, conditions, declarations or print statements, when you type an abbreviation. You expand a snippet by typing its abbreviation and pressing Tab. It is aimed at IntelliJ IDEA users writing source code.
- Tool
- JetBrains Live Templates
- Made by
- JetBrains
- Official site
- jetbrains.com/help/idea/using-live-templates.html
- Category
- IDE and terminal snippets
Who makes JetBrains Live Templates
Live templates are made by JetBrains as part of IntelliJ IDEA. They are documented in the IDE's help, and the official documentation page is linked below.
Official website: jetbrains.com/help/idea/using-live-templates.html
What JetBrains Live Templates is for
Live templates exist to insert common constructs into code without typing them out in full. Examples named in the documentation are loops, conditions, declarations and print statements.
A snippet is expanded by typing its abbreviation and pressing Tab. Where a template has variables, pressing Tab moves between them, and Shift+Tab moves back to the previous variable.
Who JetBrains Live Templates is for
The vendor describes the audience as IntelliJ IDEA users writing source code. Anyone who finds themselves typing the same construct repeatedly in the editor is the intended user.
Because templates are grouped by context, usually by language, the feature suits people who work across more than one language in the same IDE.
Notable capabilities
Live templates come in several kinds and are managed from a single settings page. The points below summarize what the documentation describes.
- Simple templates: these contain only fixed plain text that replaces the abbreviation.
- Parameterized templates: these contain variables that enable user input or are calculated automatically.
- Surround templates: these wrap selected code with user-specified text. You can wrap selected code using the Select Template popup, opened with Ctrl+Alt+J.
- Tab navigation: Tab moves between template variables and Shift+Tab goes back to the previous one.
- Settings management: templates are configured on the Editor | Live Templates settings page, where you can enable, disable, edit and create them.
- Context grouping: templates are grouped by the context where they can be used, usually by language.
- Abbreviation rules: each template has an abbreviation made of alphanumeric characters, dots and hyphens, unique within its group. The same abbreviation can be used in different groups and expand to different constructs depending on context.
- Restoring defaults: modified default templates can be restored to their default settings.
How JetBrains Live Templates fits IDE and terminal snippets
In the category of IDE and terminal snippets, live templates are the IDE-side approach: snippets live inside the editor and expand from a short abbreviation, with context deciding which template applies.
Within Snipspire's wider niche of snippet managers, code paste and developer snippet tools, live templates cover code you insert while typing in IntelliJ IDEA, rather than code you store and share elsewhere. The documentation also mentions postfix code completion, which is similar to live templates but transforms the current expression without selecting it.
Frequently asked questions
What are live templates in IntelliJ IDEA?
Live templates insert common constructs into code, such as loops, conditions, declarations or print statements. You type an abbreviation and press Tab to expand the snippet.
How do I use a live template?
Type the template's abbreviation and press Tab to expand it. If the template has variables, Tab moves to the next one and Shift+Tab moves back to the previous one.
Can live templates wrap selected code?
Yes. Surround templates wrap selected code with user-specified text, and you can apply them from the Select Template popup opened with Ctrl+Alt+J.
Where do I edit live templates?
Live templates are configured on the Editor | Live Templates settings page. There you can enable, disable, edit and create templates, and restore modified default templates to their default settings.
Can the same abbreviation do different things?
Yes. An abbreviation must be unique within its group, but the same abbreviation can be used in different groups and expand to different constructs depending on context.
Snipspire is independent and is not affiliated with JetBrains. Product names belong to their owners. Features change; confirm details on the official website.