Sublime Text 2 - Default Document Type

后端 未结 3 1263
难免孤独
难免孤独 2020-12-16 02:36

Is there a way to set a default document type when saving a NEW FILE? I created several new files and I want to have a default value of .txt when saving a NEW FILE.

相关标签:
3条回答
  • 2020-12-16 03:22

    This plugin does it:

    https://github.com/spadgos/sublime-DefaultFileType

    seems pretty great.

    Edit:

    Ok, two things, there currently seems to be a small bug so the text file syntax is not being correctly picked up due to the whitespace in the filename. In addition you need to set the "use_current_file_syntax" to false, (otherwise the new file will default to whatever filetype you have open already when you hit Ctrl-N)... So the fix/workaround is this:

    Put the following code in: Packages/User/default_file_type.sublime-settings

    { "default_new_file_syntax": "Packages/Text/Plain_text.tmLanguage",   
    "use_current_file_syntax": false }
    

    NOTE THE UNDERSCORE.

    Next, find the "Plain text.tmLanguage" file and copy and rename it (in the same folder) as "Plain_text.tmLanguage". [be sure to copy/duplicate it, do not just rename it, as it may have dependancies]

    Restart, just to be sure, and this should do the trick. Also note this plugin only works for new files created with Ctrl-N.

    0 讨论(0)
  • 2020-12-16 03:28

    Working after these steps:

    1.Uninstalled

    2.Installed using Package Control

    3.Test using default install (type Jave) <-- worked

    4.Copy and Renamed file Sublime Text 2\Packages\Text\Plain text.tmLanguage > Sublime Text 2\Packages\Text\Plain_text.tmLanguage

    5.Changed file Sublime Text 2\Packages\Default File Type\default_file_type.sublime-settings >

    `{ "default_new_file_syntax": "Packages/Text/Plain_text.tmLanguage", "use_current_file_syntax": true }`
    

    -- All working.

    I did not need to copy any files into the 'Packages/User' folder

    @fraxel _ Thanks for all the help and quick response.

    0 讨论(0)
  • 2020-12-16 03:30

    Create a new plugin Tools > Developer > New Plugin...

    Paste this in:

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

    Save and call it NewTabSyntax.py. New tabs will now default to Powershell.

    You can change the syntax to whatever you prefer. To find out the "path" of a particular syntax, simply open a file of that syntax, open the console (View > Show Console) and type:

    view.settings().get('syntax')
    
    0 讨论(0)
提交回复
热议问题