Kate Snippets

Martin Gergov

T.C. Hollingsworth


Kate Snippets is a plugin used to save you some time by adding support for so-called "snippets" (re-usable source code, machine code or text). The plugin also supports code completion and QtScript.

Menu Structure

ViewTool ViewsShow Snippets

Shows snippets panel containing all snippets in your repository that are for the currently opened file type.

Snippets panel

The Kate snippets panel.

The panel for Kate Snippets.

In the panel you should see a list of snippet repositories, along with options to create your own, get them from the Internet or load them from a local file. Each repository has a checkbox that can be used to activate or deactivate it. There are also buttons to edit and delete existing repositories.

Loading Snippet Repository Files

You can download snippet repositories from the Internet. Just click Get New Snippets and a window with a list of snippet repositories will open. After downloading the desired snippet, make sure that you have activated it.

You can also load snippet repositories from a local file using the file browser at the bottom of the panel. Click Copy to repository when finished.

Creating and Editing Snippets

The snippet editor.

The snippet editor interface.

To create a new snippet repository, click New Snippet File. You should now see dialog that asks for name of the snippet file, license and author. After choosing the desired options, click Create, and the snippet editor will open.

The snippet editor contains the following options:

File Type

Select the file type(s) you want the snippet repository to apply to. It is set to * by default, so the repository applies to all files. You can change it to something like C++ for instance, or select from a list by hitting the Edit. You can specify more than one file type by separating them with ;.


Enter the name(s) of the author(s) of the snippet file.

Snippets List

Contains all snippets defined in the snippet file. You can simply click on a snippet listed there to edit it.

Add (+)

Used to add a new snippet.

Delete (-)

Used to delete a snippet.


Appears in the list of snippets in the tool view and is also searched when using the code completion feature.

Display Prefix, Display Postfix, and Display Arguments

Used to display helpful information while using code completion. The prefix and postfix are displayed before and after the name, while the arguments are displayed in parenthesis immediately after the name.

Snippet Content

Reusable text or code. This is what appears in your document when the snippet is used.

In Snippet Content you can specify variables with ${name} or %{name}. These can be filled by QtScript or when the snippet is used. There is a special variable - ${cursor} or %{cursor} - which automatically sets the cursor to its first occurrence.

Using Snippets

Accessing Kate Snippets from a tool view and a drop down menu.

Selecting from a list of snippets.

You can call snippets in two ways:

  • By choosing the snippet from the tool view.

  • While writing, you can press Ctrl+Space, which will display all the snippets in a convenient window from which you can choose from. You may enter the beginning of the snippets name before or after pressing this key combination, which provides functionality similar to code completion.

If the snippet contains variables (besides ${cursor}) the cursor will automatically go to the first occurrence of a variable and will wait for you to write something. When you are done, you can press Tab to move to the next variable, and so on.

Thanks and Acknowledgments

Kate Snippets was written by Joseph Wenninger.

Special thanks to Google Code-In 2011 participant Martin Gergov for writing much of this section.