Generate custom code constructs using live templates
IntelliJ IDEA provides a multitude of predefined live templates for many common code constructs. You can also define custom templates to cover use cases specific to your workflow.
Insert a live template
Place the caret at the place where you want the template to expand.
Type the template abbreviation and press the invocation key (usually Tab by default). Alternatively, on the suggestion list and select the necessary template.menu, click Ctrl+J to open the
If the selected template requires user input, the corresponding field is highlighted. Type the necessary value and press Enter or Tab to complete input and move to the next input field. After completing all input fields, the caret moves to the end of the construct (or to the
$END$marker if the marker is defined in the template code), and the editor returns to the regular mode of operation.
You can also wrap fragments of code using surround templates.
Surround a block of code with a live template
Select a piece of code to be surrounded.
On the suggestion list and select the necessary template.menu, click Ctrl+Alt+J to open the
Using live templates for smart completion of parameters in function calls
To enable smart completion of parameters:
In the Editor, then General, and then Smart Keys.dialog Ctrl+Alt+S, click
Select the Enable smart function parameters completion checkbox in the PHP group.
To use smart completion templates for functions:
Type the params keyword as the first parameter in the function call.
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 Enter or Tab. To move to the previous parameter, press Shift+Tab.
The completion list contains variables from the local scope in the following order: with the same type, with a similar name, defined nearby. You can always switch to the usual completion mode by pressing Ctrl+Space or just typing anything that is not in the list. Variables with similar names are inserted automatically.