Use live templates to insert common constructs into your code, such as loops, conditions, various declarations, or print statements.
To expand a code snippet, type the corresponding template abbreviation and press ⇥. Keep pressing ⇥ to jump from one variable in the template to the next one. Press ⇧ ⇥ to move to the previous variable.
If you do not know the necessary abbreviation, press ⌃ J to open a list of templates available in the current context.
Types of live templates
The following types of live templates are distinguished:
Simple templates contain only fixed plain text. When you expand a simple template, the text is automatically inserted into your source code, replacing the abbreviation.
Parameterized templates contain variables that enable user input. When you expand a parameterized template, variables are either replaced by input fields for the user to specify manually, or calculated by AppCode automatically.
Surround templates wrap a block of the selected code with the text specified by the user. For example,
Texpands into a pair of tags, for which you can specify a name. You can also select a block of code, then press ⌃ ⌥ J to open the Select Template popup and select the
Ttemplate to wrap the selection with a pair of tags.
Configure live templates
To configure live templates, open the Editor | Live Templates page of the IDE settings ⌃ ⌥ S. On the Live Templates page, you can see all the available live templates, edit them and create new templates.
Templates are grouped according to the context where they can be used (usually, by the corresponding language). To move a template to another group, right-click the template, select Move, and then select the necessary group name.
Each live template is defined by an abbreviation containing alphanumeric characters, dots, and hyphens. The abbreviation must be unique within a group, but the same abbreviation may be used in different groups and expand to different constructs according to the context of the corresponding group. Abbreviations of modified default templates are shown in the list with blue font.
Restore a modified template to the default settings
On the Live Templates page of the Preferences dialog, right-click the template which you want to restore and click Restore defaults.
Share live templates
AppCode stores definitions of custom live template groups and templates added to predefined template groups in automatically generated XML configuration files.
For a custom group, the file contains definitions of all the templates the group includes.
For a modified predefined group, the file contains definitions of the added (or modified) live templates only.
Live template group configuration files are stored in the templates folder of the IDE configuration directory ~/Library/Preferences/AppCode2021.2.
To share the live templates, you can manually copy and paste the neccessary configuration files to the templates folder. Alternatively, you can use the AppCode functionality for sharing the IDE settings, including live templates (IDE Settings Sync plugin, settings repository, or exporting/importing the settings as an archive). Learn more in the Share IDE settings section.