Templates

Geany supports the following templates:

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

WildcardDescriptionAvailable in following templates
developerThe name of the developer.filetypes, file header, function description, ChangeLog entry, bsd, gpl
initialThe 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
mailThe email address of the developer.file header, function description, ChangeLog entry, bsd, gpl
companyThe company the developer is working for.filetypes, file header, function description, ChangeLog entry, bsd, gpl
yearThe current year in the format: YYYYfiletypes, file header, function description, ChangeLog entry, bsd, gpl
versionThe initial version of a new file.filetypes, file header, function description, ChangeLog entry, bsd, gpl
dateThe current date in the format: YYYY-MM-DDfiletypes, file header, function description, ChangeLog entry, bsd, gpl
untitledThe string "untitled" (this will be translated to your locale), used in filetype templatesfiletypes, file header, function description, ChangeLog entry, bsd, gpl
geanyversionThe actual Geany version, e.g. "Geany 0.11" filetypes, file header, function description, ChangeLog entry, bsd, gpl
datetimeThe current date and time in the format: DD.MM.YYYY HH:mm:ss ZZZZfile header, function description
filenameThe filename of the current file. Only available for the file header template.file header
gplThis wildcard inserts a short GPL notice.file header
bsdThis wildcard inserts a short BSD licence notice.file header
functionnameThe function name of the function at the cursor position. This wildcard will only be replaced in the function description template.function description
fileheaderThe 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 .