b00kgrrl
b00kgrrl

Reputation: 597

Sublime Text 3 - Default to Text File Type

I am using SublimeText 3 and I would like new files to be created in plain text format (i.e. default to a .TXT extension when they are saved).

I followed the instructions in this post.

I created a new file called "default_file_type.sublime-settings" and placed it in the "Packages/User" directory. The file had the following content:

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

I also unzipped the "Text.sublime-package" file, created a new directory called "Text", and renamed the "Packages/Text/Plain text.tmLanguage" file to "Packages/Text/Plain_text.tmLanguage"

When I open SublimeText, I get an error:

Error loading syntax file "Packages/Text/Plain_text.tmLanguage": Unable to load Packages/Text/Plain_text.tmLanguage

When I save a new file, it does not save in .TXT format.

Where did I go wrong?

Upvotes: 1

Views: 3245

Answers (1)

Enteleform
Enteleform

Reputation: 3823

The solution you posted requires several workarounds, and tmLanguage is in the process of being phased out by sublime-syntax.

The following steps implement the new sublime-syntax standard & a simple EventListener that executes when new files are created.


Save the following code as Packages/NewFileSyntax/TXT.sublime-syntax:

%YAML 1.2
---
name: TXT
comment: TXT documents
file_extensions:
  - txt
scope: txt.source
contexts:
  main:
    - match: .*
      scope: text.plain

Save the following code as Packages/NewFileSyntax/NewFileSyntax.py:

import sublime, sublime_plugin

class NewFileSyntax( sublime_plugin.EventListener ):
  def on_new( self, view ):
    view.set_syntax_file( "Packages/NewFileSyntax/TXT.sublime-syntax" )

Upvotes: 1

Related Questions