Sublime Forum

Why does Sublime Text save txt files without an extension?

#1

In the Sublime itself (at the bottom right) I choose Plain text, I close it when I close it. In the save window, by default, it’s All Files, I choose Plain Text, I give the name, the result is still without the extension. And this only with txt. With others, everything is fine.
Why?

0 Likes

#2

Why?

Plain text is a loose term that refers to any file that contains data that may be interpreted as text with the right encoding (encodings like ASCII, UTF-8, UTF-16LE).

Therefore, almost any file is plain text:

  • JSON is plain text,
  • Javascript is plain text,
  • XML is plain text,
  • Markdown is plain text,
  • HTML is plain text,
  • etcetera.

Here are some examples of commonly named files with no extension that are also plain text:

  • The README file of a code repository
  • The LICENSE file of a code repository
  • The TODO/NEWS/AUTHORS file of a code repository

Almost no character encoding has consecutive zeroes as a valid character. So, non-plain text files, also called binary files are ones with consecutive zero characters in them. Any executable, or any JPG, PNG, etc, is binary.

So, I hope you can see now that making Sublime Text save plain text files with the extension .txt by default is an arbitrary choice. The only reason to do so is to help the operating system choose a specific application for you to open that file with if you double-click on it in your operating system’s file browser.

1 Like

#3
3 Likes

#4

Thank you very much!

The solution from post above for those who will view this topic:
With a plain text file open, choose Preferences -> Settings - syntax specific, then in the right tab add the line
"default_extension": "txt"

PS. I added to User settings

4 Likes

#5

Thanks for the tip now my default is PHP and it works well.
Still, I don’t get what the “Save as type” select is for as I have to explicitly add the extension in the “File name” field. Whatever type I select it is saved without extension.

1 Like

#6

Thanks a lot, it works as you said in Sublime Text 3

  1. Preferences → Settings - syntax specific
  2. Add “default_extension”: “txt” to it or any other file extension (example: html or php)
    Screenshot:
0 Likes