They offer different flash templates with latest features.

Forgot password
Written by:
Score: 5
votes: 7
Format: Article

 Setting Sublime Text 2's Default File Syntax

I created this tutorial for my favourite text editor because I found that everytime I pressed "ctrl+n" in Sublime Text 2, the default text would just be "Plain Text".  It got really frustrating for me everytime I just want to get writing but instead, I have to go and change the settings.  I was also told to press the bottom right corner (where the programming-language menu is) and change it from there, but that didn't work too. 

**This guide assumes that you have installed Sublime Text 2 with this guide:**

So here is the fool-proof way:

First we need to get the Package Manager for Sublime Text 2, you can do this by pressing " ctrl + ` "and it will bring up a text area:

In here the empty line, paste the following code into it, then press "enter": 

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen(''+pf.replace(' ',' ')).read()); print 'Please restart Sublime Text to finish installation'

Here is what it should look like before you press enter:


After Sublime Text 2 has been restarted, press Preferences → Package Control


From here, a dialogue box will pop up with a field for text.  In that field, type in "Install Package":


Let it run and a repository of available plugins will show itself:

The one we are interested in for our setting our default syntax is the one aptly named "DefaultFileType".  It should be found in between "DCPU-16" and "DeleteBlankLines", but because I have already installed it before this tutorial, it doesn't show up for my screenshot purposes.  After clicking "DefaultFileType" it will install itself.

We aren't quite done yet, we need to go under the hood of our Linux car and tinker around with the help of the command line.

Fire up your terminal and enter:

cd ~/.config/sublime-text-2/Packages/

cd Default\ File\ Type/

and if you enter ls you should see something that resembles this:


The file we are interested in is "default_file_type.sublime-settings".  So go ahead and type in nano default_file_type.sublime-settings

And you will be greeted with this:

We have two fields to edit: 

"default_new_file_syntax" should contain the path that contains the language of your choice in the ".tmLanguage" format.  The path can be found in the Packages folder.

"use_current_file_syntax" means that from now on (if the value is true), when you press "ctrl+n" the new file that opens will have the same syntax as the current file you are on. 


If you are still unsure what to put for the "default_new_file_syntax" let me walk you through an example:

from where we left off, let's go to our "Packages" folder. 

cd .. and you will see what I'm talking about:

 Let's say I wish to change my default language over to Java:

cd Java then ls and we should see the "Java.tmLanguage".  Remember this, because our new path for the "default_new_file_syntax" variable in the "default_file_type.sublime-settings" file will be:


From here, you can simply save and exit, and from now on, when you fire up Sublime Text 2 and press "ctrl + n" you will have the syntax of your choice waiting for you!


Tags: Sublime Text 2, Text Editor, Syntax
Created: 5 years ago.
Last edited: 5 years ago.
Reviewed: 5 years ago.
Read 0 times.


No comments so far.

Other tutorials from 3xOSC

No other tutorials.