On this page:
- Introduction
- Inserting a live template
- Using live templates for smart completion of parameters in function calls
Introduction
This page describes how to generate source code using live templates.
Using Live Templates enables you to create such code constructs as the main() method, iteration over an array, , typical variable declarations, output statements, Emmet, etc.
To explore the list of available live templates, in the Settings/Preferences dialog, open the Live Templates page.
Inserting a live template
- Place the caret at the desired position, where the new construct should be added.
- Do one of the following:
- On the main menu, choose .
- Press ⌘J⌘J^ J^ J.
- Type some initial letters of the template abbreviation to get the matching abbreviations in the suggestion list. Note that the suggestion list may contain same abbreviations for different templates.
- From the suggestion list, select the desired template.
While the suggestion list is displayed, it is possible to view Quick Documentation
for the items at caret, by pressing F1⌃J⌥Button2 Click^ Q^ Q.

- Press the template invocation key (this may be Space, ⇥⇥⇥TabTab or ⏎⏎⏎EnterEnter, depending on the template definition). The new code construct is inserted in the specified position.
- If the selected template is parametrized and requires user input, the editor enters the template editing mode and displays the first input field highlighted with the red frame. Type your value in this frame and press ⏎⏎⏎EnterEnter or ⇥⇥⇥TabTab to complete input and pass to the next input field. After completing the last input field, the caret moves to the end of the construct, and the editor returns to the regular mode of operation.
It is also possible to type a template abbreviation, and then press ⌘J⌘J^ J^ J.
Using live templates for smart completion of parameters in function calls
This feature is supported in Ultimate edition only.
The following is only valid when PHP Plugin is installed and enabled!
In the PHP context, you can use an “automatic” live template that provides completion lists for the parameters passed into functions, methods, or class constructors.
-
To activate this functionality:
- Open the Settings / Preferences Dialog by pressing ⌘,⌘,⌘,⌥ F7^ ⌥ S or by choosing for Windows and Linux or for OS X. Expand the Editor node, and then click Smart Keys under General.
- On the Smart Keys page that opens, select the Enable smart function parameters completion check box in the PHP area.
-
To invoke the magic live template, type the params keyword as the first parameter
in the call of the function, method, or class:
IntelliJ IDEA displays a live template where the parameters are automatically completed with the variable names defined in the function declaration. To move to the next parameter, press ⏎⏎⏎EnterEnter or ⇥⇥⇥TabTab. To move to the previous parameter, press ⇧⇥⇧⇥⇧⇥⇧ Tab⇧ Tab.
The completion list contains variables from a local scope in the next order: with the same type, with a similar name, defined nearby. You can always switch to the usual completion mode by pressing ⌃Space⌃Space⌃Space^ Space⌥ Slash or just typing anything which is not in the list. Variables with similar names are inserted automatically.