How do I see the current encoding of a file in Sublime Text?
Asked Answered
T

6

388

How do I see the current encoding of a file in Sublime Text?

This seems like a pretty simple thing to do but searching has not yielded much. Any pointers would be appreciated!

Tibetan answered 24/4, 2013 at 15:20 Comment(0)
D
651

Since this thread is a popular result in google search, here is the way to do it for sublime text 3 build 3059+: in user preferences, add the line:

"show_encoding": true
Dys answered 18/12, 2013 at 12:11 Comment(6)
Clicking the new status bar panel also allows you to conveniently change it or re-open the file in a different encoding.Showy
I don't have that setting but ST3 shows the encoding next to the name on the status bar every time I save a file.Larkin
@bfred.it: Yes, as described in Gregordy's answer, but it's important to note that the information only shows for about 4 seconds.Wizard
This works, and is permanently showing in the status bar. Since you're interested in the the encoding, you may also be interested in the line endings. (unix, windows) Activate this with: "show_line_endings": true,.Undetermined
Why isn't this enabled by default... +1Frambesia
I think @DanielLidström because most people work in UTF-8 and superfluous info is not better. I have very specific reasons to occasionally have to be aware of the file encoding, so activating this is great.So
P
325

Another option in case you don't wanna use a plugin:

Ctrl+` or

View -> Show Console

type on the console the following command:

view.encoding()

In case you want to something more intrusive, there's a option to create an shortcut that executes the following command:

sublime.message_dialog(view.encoding())
Peptone answered 24/4, 2013 at 18:5 Comment(6)
@calumbrodie Do you have any file opened? I'm using ST3 and it works fine. I get "Undefined" only when I execute the command and there is no file (or tab) opened.Regimentals
Yes, but it only happens with particular files. I think if the file doesn't have a defined encoding maybe.Tubby
While calling view.encoding() I got UTF-8 but while calling print sys.stdin.encoding from Python I got NoneLangevin
@Tubby You can try my solution mate, much quicker in my sense ; )Scammon
'Undefined' appears to imply: (a) the file has no BOM (byte-order mark), (b) the file contains only single-byte ASCII chars., (c) the file has not yet been saved by Sublime Text in this session. Once saved by ST , it then reports 'UTF8' until closed (on re-opening the guessing starts over).Wizard
I would ask how can I "create an shortcut that executes the following command: sublime.message_dialog(view.encoding())" as suggested by Hugo. ThanksChafee
D
45

With the EncodingHelper plugin you can view the encoding of the file on the status bar. Also you can convert the encoding of the file and extended another functionalities.

Demo

Deliladelilah answered 24/4, 2013 at 17:4 Comment(0)
S
39

For my part, and without any plug-in, simply saving the file either from the File menu or with keyboards shortcuts

CTRL + S (Windows, Linux) or CMD + S (Mac OS)

briefly displays the current encoding - between parentheses - in the status bar, at the bottom of the editor's window. This suggestion works in Sublime Text 2 and 3.

Note that the displayed encoding to the right in the status bar of Sublime Text 3, may display the wrong encoding of the file if you have attempted to save the file with an encoding that can't represent all the characters in your file. In this case you would have seen an informational dialog and Sublime telling you it's falling back to UTF-8. This may not be the case, so be careful.

Scammon answered 22/12, 2014 at 4:35 Comment(1)
The big queston is why Sublime Text doesn't allow you to enforce or convert encodings easily in cases like that. I'd prefer if Sublime just removed offending characters rather than change the encoding as I must use the encoding I had first. The encoding switch renders all my work useless.So
G
9

ShowEncoding is another simple plugin that shows you the encoding in the status bar. That's all it does, to convert between encodings use the built-in "Save with Encoding" and "Reopen with Encoding" commands.

Geddes answered 22/10, 2013 at 0:14 Comment(0)
Y
1

plugin ConverToUTF8 also has the functionality.

Yusem answered 26/9, 2013 at 3:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.