# Code Templates

You can insert a predefined piece of code called a code template by typing the template name and pressing `F2`. To display the list of available templates, press `Ctrl+J`.

For example, if you type `for` and press `F2` the editor adds:

```
for  =  to  // step 1

end // for
```

## Types of Templates

There are two types of templates: *shared* and *exclusive*. Shared templates are available across all [edit modes](/edit-modes.md). They are contained in the file `data\templates.txt`. Exclusive templates are designed specifically for the current edit mode. A path to the exclusive template file can be customized with the [`template`](/edit-modes.md#templates) key in the mode configuration:

```
<templates type="default">@sb:\data\gta3\templates.txt</templates>
```

The editor merges the content of shared and exclusive templates in a single list. Exclusive templates have priority over the shared with the same name.

## File Syntax

Each template file has the following syntax:\
A template name is written in a separate line. The equal sign `=` follows the name. After the equal sign you can also add a short hint. The template code starts at the next line, each line begins with the equals sign. The cursor position is marked with the `|` character.

## Adding a New Template

It's also possible to add a new template from the editor. Select the code and click the `Service->Add template` menu.

![](/files/-MDlMQiTlVgy3xpUEGxS)

Enter a name of the template, a description (optionally) in the dialog window, choose the type of the template, and press the `OK` button. The template is ready to use.

Custom templates are saved in either `data\templates.custom.txt` (*custom shared templates*) or in `data\<edit mode>\templates.custom.txt`(*custom exclusive templates*). The latter can be customized in the [modes configuration](/edit-modes.md#templates).

{% hint style="info" %}
The option to save a template only for current mode becomes available if `modes.xml` has a file path defined in `<template type="custom">`tag.
{% endhint %}

{% hint style="info" %}
A template with the name `CLEO` unlocks the "New CLEO Script..." item in the main menu. The editor uses this template as the content for a newly created file.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sannybuilder.com/edit-modes/code-templates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
