Creating/editing templates with frequently used code
Create →templates in order to insert frequently used sections of code within the ST-editor by using content assist.
How to create a template for the ST-editor:
In menu Window, select Preferences. Expand the group ST-Object and select Templates.
Click New...
In the dialog, enter the following data as required, then click OK.
the template name in field Name
the context type for the new template in the Context drop down list
The context determines where the template can be used and the set of available template variables.check for Automatically insert so that content assist automatically inserts the template, if it is the only proposal available at the code position.
a description for the new template in field Description
This description is displayed as information in the list of the content assist.the code for this template in field Pattern
one or more template variables in field Pattern
Example: The pattern (* created on ${date} by ${user} for ${word_selection} *) creates a comment based on the selected word and adds the date and the ID of the user.
For each required template variable: Click Insert Variable... and double-click one of the items in the provided list. The list also provides an item to create a new template variable (in field Pattern, enter a name for the inserted, new template variable).A template variable marks an editable location in the code of the template. They can be resolves to a concrete value when the code of the template is evaluated in its context. They can also provide a list of alternative proposals valid at the given location.
For instance, a template variable within a declaration template stands in for the identifier that is needed within a declaration.
How to edit an existing template for the ST-editor:
In menu Window, select Preferences. Expand the group ST-Object and select Templates.
Select the template that you want to edit.
Click Edit...
In the dialog, edit the data as required (accordingly to creating a template), then click OK.
This creates a new template based on the current template: Change the template name in field Name.
In addition to creating and editing the templates, the preferences for the templates provide the following possibilities:
Possibility |
Button in preferences |
removing the selected templates from the user preferences |
Remove |
restoring templates recently removed from the user preferences |
Restore Removed |
removing the last edits made to the selected template and restoring the previous state |
Revert to Default |
importing a template |
Import... |
exporting the selected template |
Export... |