Postfix completion
With postfix templates, you can transform an already-typed expression to a different one based on a postfix after the dot, the type of the expression, and its context. GoLand includes a set of predefined postfix completion templates that you can use for other programming languages as well. You can copy, enable, and disable these templates.
In the Settings dialog (CtrlAlt0S), open Editor | General | Postfix Completion and select the Enable postfix completion checkbox.
Enable or disable postfix templates for the selected language.
Set the Tab, Space, or Enter key to expand postfix templates.
Type an expression and then type a postfix after a dot. For example, type
.if
.Press Tab.
Before
func m(b bool) {b.if}After
func m(b bool) {if b {}}The initial expression gets wrapped with an
if
statement.
Postfix completion options are shown as part of the basic completion suggestion list. To see a full list of postfix completions applicable in the current context, press Ctrl0J.
You can edit the predefined postfix templates, for example, to replace a long key with a shorter one, or to expand the list of applicable expression types.
Press CtrlAlt0S to open settings and then select Editor | General | Postfix Completion.
Double-click a template name in the tree or click the
icon above the list of templates and edit it as required.
Press CtrlAlt0S to open settings and then select Editor | General | Postfix Completion.
Click the Add button (
) on the toolbar.
In the Create New Template dialog that opens, specify Key, a combination of symbols after the dot that will invoke the template.
Select which expression types the new template will be applicable to, and type the target expression in the following format:
$EXPR$ <target_expression>
, for example,$EXPR$ != nil
.Inside the template, you can use two predefined variables:
$EXPR$
refers to the target expression (the expression preceding the dot).$END$
defines the position of the caret after the template has been invoked.
The Apply to the topmost expression checkbox applies your template to the entire expression ignoring the scope. So you do not need to select the scope for the template each time.
tip
Postfix code completion is similar to live templates which allow you to create custom constructs to be used anywhere inside your code. The difference is that live templates insert predefined code snippets, while postfix completion wraps or modifies existing expressions.
Thanks for your feedback!