Showing posts with label sublime text. Show all posts
Showing posts with label sublime text. Show all posts

Sunday, April 15, 2018

Template File for Sublime Text - Customization

It is always easy to have file templates when we need have them created repeatedly. Today I am going to show file templates in Sublime Text 2.

SublimeFileTemplates - Installation and Usage

To create a file using a template, I have used Sublime File Templates Package for the Sublime Text. Installation and Usage is explained in the GitHub page of the package.

When you install the package, by default, some templates will be installed for some of the file types. If you are not satisfied with the default template, you have an option to customize it.

Here I am going to explain the template customization for the file type *.java

Template Customization for Java

You can locate the templates files for file types at
  • ~/Library/Application Support/Sublime Text 2/Packages/FileTemplates/Templates (Unix)
  • C:/Users//AppData/Roaming/Sublime Text 2/Packages/FileTemplates/Templates (windows)
There you can find template settings file - java.file-template and actual template file - java.java.

java.file-template

This file looks like
Here you can add as much arguments as you need, they will be asked in the order specified and can be used in the template file.

java.java

This is actual template file. When you create the file using this plugin, this file will look like this template file. In this template you can use the arguments defined in java.file-template. Following is an example template file
The parameter $name in the template file is read from the template settings file java.file-template.

You might have also observed other parameters as $date2, $author and $year. Where are they coming from? Well these are defined in the file ~/Library/Application Support/Sublime Text 2/Packages/FileTemplates/FileTemplates.sublime-settings. You can again add as much attributes as you need and use in your template file.

FileTemplates.sublime-settings