Templates and Snippets[edit]

Templates and snippets can boost your productivity by supplying you with some code snippets right at your fingertips (by pressing CTRL+Space in the editor).

Templates must be assigned a category (CL, RPG or Snippets). A template with the category CL will only be available in a CL editor (either QSYS or Stream File). Templates with the category Snippets are only available in the Snippets view.

Templates[edit]

Templates are small pieces of code that you can insert while editing text. Typically, templates are selected when pressing CTRL+SPACE. Just type the first few letters of the template and it will be selected:

Miw templcompletion.gif

Snippets[edit]

Snippets are larger pieces of code that can be inserted via the Snippets View

The Snippets view shows you all defined snippets. You will probably want to have your code skeletons for programs and procedures in that view for easily setting up and start the development of your new program.

Imiw snippets.png

Creating Templates and Snippets[edit]

Templates and snippets can be easily created in the preferences, see Main Menu → Window → Preferences → Editor → Templates.


Miw snip pref.png


Template Variables[edit]

Templates are not only static text but can also have variable content, variables. Template variables start with ${ and end with }. E.g.:

${description}

There are five special variables:

  • ${date} -- is resolved to the current date
  • ${user} -- is resolved to the current license user
  • ${cursor} -- this is the position where the cursor is placed after exiting the special editing mode
  • ${word_selection} -- is resolved to the currently selected text in the editor (it may span multiple lines)
  • ${line_selection} -- is resolved from the first character of the first line to the last character of the last line from the selected text

The template variables are placeholders that will be resolved to a value or will be placed into the source code as placeholders which the user can fill after inserting the template. After inserting the template the editor is switched to a special mode where the user can enter a value for each non-resolved placeholder. The TAB character is used to move to the next placeholder. ALT+TAB is used to move to the previous placeholder.

If a placeholder exists multiple times in a template all those occurrences are edited simultaneously.

Surround With Editor Support[edit]

The context menu of each editor has also the menu entry Surround With. Under this menu entry are the templates listed which contain either the variable ${word_selection} or ${line_selection} and from this menu entry can these templates be used.

Miw word template.png


Miw word compl.gif

Import / Export[edit]

The templates section in the Preferences dialog has buttons for importing and exporting templates. The templates are stored in a text file in XML format for an easy exchange of templates.

Templates are identified by their name. If a template is imported into an editor installation any existing template with this name will be replaced with the new one.