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
<template>
<!-- Or you set a path to a seperate Template File here -->
<file>java.java</file>
<!-- The filename for the new File, you can use the arguments to make it dynamic -->
<filename>$name.java</filename>
<!-- Optional: Add as much arguments as you need, they will be asked in the order specified -->
<arguments>
<name>Name (without extension):</name>
</arguments>
</template>
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
/* File: $name.java
* Created: $date2
* Author: $author
*
* Copyright (c) $year https://manandharsabbirk.appspot.com
*/
import java.io.*;
import java.util.*;
public class $name{
//---------------------------------------------------------------------------------
/**
* main method
*/
public static void main (String [] args) throws IOException{
Scanner input = new Scanner(System.in);
} // main
//---------------------------------------------------------------------------------
} // $name
view raw java.java hosted with ❤ by GitHub
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

{
"excluded_dir_patterns": [
"tmp", "|.git", "|.svn"
],
"attrs": {
"author": "Sabbir Manandhar",
"company": "Hogwart",
"email": "manandhar.sabbir@gmail.com",
"github": "github.com/leosabbir"
},
"creation_time": {
"day": "%d",
"month": "%m",
"year": "%Y",
"short_weekdayname": "%a",
"weekdayname": "%A",
"short_monthname": "%b",
"date": "%d/%m/%Y",
"date2" : "%Y-%m-%d",
"time": "%H:%M:%S"
}
}







3 comments:






  1. Pretty great post. I simply stumbled upon your blog and wanted to mention that I have really loved surfing around your blog posts. Great set of tips from the master himself. Excellent ideas. Thanks for Awesome tips Keep it
    sublime-text-crack
    kaspersky-total-security-crack
    hitman-pro-crack
    avs-video-editor-crack
    total-commande-crack

    ReplyDelete
  2. Structure and Content. Use the introduction to get the reader's attention and interest in the topic. Define the problem you are going to discuss and provide a short overview on what you think and why. Summarize the most important arguments that best support your opinion.Outstanding Good for you Phenomenal Good reasoning Praiseworthy Good thinking Prestigious work Good work/Good job Proper Grand Purrrfect Great Remarkable Great going Resounding results Honorable Respectable I appreciate your cooperation. Right on target I appreciate your help.Thank you so much for sharing all this wonderful info with the how-to's!!!! It is so appreciated!!! You always have good humor in your posts/blogs. So much fun and easy to read!
    HitmanPro Crack
    IDM Crack
    Voicemod Pro Crack
    Pixelmator Pro Crack

    ReplyDelete
  3. Download Software for PC & Mac
    You make it look very easy with your presentation, but I think this is important to Be something that I think I would never understand
    It seems very complex and extremely broad to me. I look forward to your next post,
    Mocha Pro Crack
    BeeCut Crack
    Blue-Cloner Crack
    Sublime Text Crack
    Video Copilot Element Crack
    PyCharm Pro Crack
    Resharper Crack
    Agisoft Metashape Pro Crack

    ReplyDelete