Templates
Prev | Chapter 4. Configuration files | Next

## Templates

Geany supports the following templates:

- ChangeLog entry

- File header

- Function description

- Short GPL notice

- Short BSD notice

- Filetype template

To use these templates, just open the Edit menu or open the popup menu by right-clicking in the editor widget, and choose "Insert Comments" and insert templates as you want.

Some templates (like File header or ChangeLog entry) will always be inserted at the top of the file.

To insert a function description, the cursor must be inside of the function, so that the function name can be determined automatically. The description will be positioned correctly one line above the function, just check it out. If the cursor is not inside of a function or the function name cannot be determined, you cannot insert a function description.

### Template metadata

Metadata can be used with all templates, but by default user set metadata is only used for the ChangeLog and File header templates.

In the configuration dialog you can find a tab "Templates" (see Figure 3.10, “Template tab in preferences dialog”). You can define the default values which will be inserted in the templates. You should restart Geany after making changes, because they are only read at startup.

### Filetype templates

Filetype templates are templates used as the basis of a new file. To use them, choose the New (with Template) menu item from the File menu.

By default, templates are created for some filetypes. Other filetype templates can be added by creating the appropriate template file and restarting Geany. You can also edit the default filetype templates.

Filetype template files are read from the `~/.geany/templates` directory, and are named '`filetype.`' followed by the filetype name, e.g. `filetype.python`, `filetype.sh`. If you are unsure about the filetype name extensions, they are the same as the filetype configuration file extensions, commonly installed in `/usr/share/geany`, with the prefix '`filetypes.`'.

The file's contents are just the text to place in the document, except for the optional `{fileheader}` template wildcard. This can be placed anywhere, but is usually on the first line of the file, followed by a blank line.

There is also a template file `template.none` which is used when the New command is used without a filetype. This is empty by default.

### Customizing templates

Each template can be customized to your needs. The templates are stored in the `~/.geany/templates/` directory (see the section called “Command line options” for further information about the configuration directory). Just open the desired template with an editor (ideally Geany ;-) ) and edit the template to your needs. There are some wildcards which will be automatically replaced by Geany at startup.

#### Template wildcards

All wildcards must be enclosed by "{" and "}", e.g. {date}.

Table 4.4. Template wildcards

Wildcard | Description | Available in following templates
--- | --- | ---
developer | The name of the developer. | filetypes, file header, function description, ChangeLog entry, bsd, gpl
initial | The developer's initials, e.g. "ET" for Enrico Tröger or "JFD" for John Foobar Doe. | filetypes, file header, function description, ChangeLog entry, bsd, gpl
mail | The email address of the developer. | file header, function description, ChangeLog entry, bsd, gpl
company | The company the developer is working for. | filetypes, file header, function description, ChangeLog entry, bsd, gpl
year | The current year in the format: YYYY | filetypes, file header, function description, ChangeLog entry, bsd, gpl
version | The initial version of a new file. | filetypes, file header, function description, ChangeLog entry, bsd, gpl
date | The current date in the format: YYYY-MM-DD | filetypes, file header, function description, ChangeLog entry, bsd, gpl
untitled | The string "untitled" (this will be translated to your locale), used in filetype templates | filetypes, file header, function description, ChangeLog entry, bsd, gpl
geanyversion | The actual Geany version, e.g. "Geany 0.11" | filetypes, file header, function description, ChangeLog entry, bsd, gpl
datetime | The current date and time in the format: DD.MM.YYYY HH:mm:ss ZZZZ | file header, function description
filename | The filename of the current file. Only available for the file header template. | file header
gpl | This wildcard inserts a short GPL notice. | file header
bsd | This wildcard inserts a short BSD licence notice. | file header
functionname | The function name of the function at the cursor position. This wildcard will only be replaced in the function description template. | function description
fileheader | The file header template. This wildcard will only be replaced in filetype templates. | filetypes

If you need any other wildcards or a special date/time format, please email the author `<enrico.troeger@uvena.de>`.

Prev | Up | Next
Filetype extensions | Home | Appendix A. Contributing to this document