Skip to content

File Templates

Trevor Williams edited this page Apr 26, 2020 · 1 revision

If you on working on a project, it is likely that you are creating files written in a similar format. Perhaps you are coding in C++ and creating header and source files with similar starting code, perhaps different only based on the filename. Rather than re-typing this code over and over, it would make sense to create a snippet containing the starting content. That way, when you create a new file, you can just enter a shortcut to setup the starting state of the file. The downside to using snippets in this way is that the snippets can be quite lengthy, cluttering up the snippet files. For these reasons, TKE has a feature called file templates.

Creating a New File from Template

File templates are essentially special, saved files that can have snippet syntax embedded at them. When a new file needs to be generated, create the new file with the File / New From Template... which will list all of the available templates to start from. Select one from the list (a preview will be shown of the template to aid in your file selection) and a file save dialog window will be displayed to allow you to name the new file. If you enter a valid name and click the “Save” button, a new file will be created, a new editing buffer will be added with the template contents added, any filename substitutions/transformations found in the template will be performed, and TKE will start snippet traversal as found within the template snippet content.

Alternatively, you can also create a new file from template in the sidebar. Select a directory where you want to put the template file and right-click to bring up the contextual menu for the directory. Select New File From Template, select the template file, and in the filename entry field at the bottom of the window, enter the filename to create (no directory is necessary).

Creating a File Template

Creating a file template is pretty straightforward. Starting with a new editing buffer, add all of the contents of the file template using any syntax that is valid snippet syntax, and use the File / Save As Template… menu option to save. You will be prompted for a template name in the entry field at the bottom of the main window. After entering the name and hitting the RETURN key, the file template will be created and available from any of the “New File From Template” options as mentioned above.

Editing/Deleting File Templates

Since file templates are stored in a specific directory managed by TKE (your home directory/.tke/templates), you can edit/delete file templates using the Edit / Templates menu. Selecting the “Edit” menu option will display the file templates in a previewer window. Simply click on one to edit the file in an editing buffer and use the “Save As Template” option (using the same name) to update its contents. To delete a template, select the “Delete” menu option, select the template from the previewer and the template will be permanently removed.

Take advantage of file templates to help save you time (and weary fingers!)

Clone this wiki locally