PyCharm 2016.1 Help

Using Postfix Templates


Postfix code completion lets you transform an already typed expression to another one based on the postfix you type after a dot, the type of the expression, and its context. This transformation is performed by expanding the postfix-specific predefined template. For example, the .if postfix applied to a boolean expression wraps it with an if statement. See more at: Postfix Code Completion.

Activating and de-activating postfix templates

When the postfix template functionality is enabled, PyCharm transforms expressions with postfixes into other expressions by expanding the corresponding postfix-specific templates.

To activate the postfix templates functionality:

  1. Open the Settings / Preferences Dialog by choosing File | Settings for Windows and Linux or PyCharm | Preferences for OS X. Expand the Editor node, and then click Postfix under General.

    The Postfix Completion page that opens shows a list of postfixes for which PyCharm can transform expressions according to postfix-specific templates. Transformation templates are shown next to corresponding postfixes. When you select a postfix, the Description pane illustrates the corresponding transformation showing the code snippet before and after the template is expanded.

  2. Select the Enable postfix templates check box and choose the key to launch template expansion from the Expand template with drop-down list.
  3. Select the check boxes next to the postfixes for which you want PyCharm to expand the corresponding templates.

To suppress expanding a template, clear the check box nex to the corresponding postfix. To block the postfix templates functionality, clear the Enable postfix templates check box.

Using postfix templates

To apply a postfix template:

  1. Type your code followed by a dot, until a suggestion list appears, or press Ctrl+J.
  2. Choose the desired postfix template from the suggestion list. If necessary, choose an expression to be surrounded or replaced.
  3. Press the expansion key, defined in the Postfix Completion page of the editor settings.

See Also

Last modified: 20 April 2016