Extending Qt Creator Manual | Snippets for Editors

Extending Qt Creator Manual 4.11.0

# Snippets for Editors

Snippets typically consist of chunks of code in a programming language (although they can also be plain text) which you would like to avoid re-typing every time. They are triggered in the same way as the completions (see Providing Code Assist).

In order to create a new group of snippets two steps are necessary:

- Register the group with TextEditor::SnippetProvider::registerGroup
- Create an XML configuration file and place it in the /share/qtcreator/snippets directory. As an example of the file format please take a look at the already available ones. The meaning and consistency rules of the fields are described below:
  - group - This is the group in which the snippet belongs in the user interface. It must match TextEditor::SnippetProvider::groupId().
  - id - A unique string that identifies this snippet among all others available. The recommended practice is to prefix it with the group so it is easier to have such control on a file level.
  - trigger - The sequence of characters to be compared by the completion engine in order to display this snippet as a code assist proposal.
  - complement - Additional information that is displayed in the code assist proposal so it is possible to disambiguate similar snippets that have the same trigger.

All XML configuration files found in the directory mentioned above are parsed by Qt Creator. However, only the ones which are associated with known groups (specified by a provider) are taken into consideration.