Sublime Text 2 Default File Type on new file

2019-02-09 15:20发布

问题:

I was looking around and the questions and answers did not seem to match what I am looking for. Anytime I open a new file it defaults to a plan text file. I mostly work with HTML files so I was wondering if there is a setting that would be changed so that when I open a new file it will default to HTML? Hope this is possible.

Rob

回答1:

Just hit Tools -> New Plugin

Then paste this over the file, hit save and call it "DefaultLanguage.py" or something

import sublime, sublime_plugin

class EverythingIsPowerShell(sublime_plugin.EventListener):
   def on_new(self, view):
      view.set_syntax_file('Packages/PowerShell/Support/PowershellSyntax.tmLanguage')

Of course, you can change the language from PowerShell to ... whatever you prefer. You just need the relative path to the tmLanguage. You can get that by opening a file in your favorite language and then open the console (View->Show Console) and type:

view.settings().get('syntax')


回答2:

pls install Package sublime-DefaultFileType https://github.com/spadgos/sublime-DefaultFileType

which will automatically sets the syntax for new files.



回答3:

It is possible with the ApplySyntax Plugin. Once it is installed (e.g. via PackageControl), you can set the ApplySyntax User Settings like that:

"new_file_syntax": "HTML",

Now if you open a new file, your default syntax will be HTML. Of course you can set every Syntax you have installed.