384

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!

the_storyteller
  • 2,335
  • 1
  • 26
  • 37
arturomp
  • 28,790
  • 10
  • 43
  • 72

6 Answers6

641

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
o.d
  • 6,534
  • 1
  • 13
  • 3
  • 15
    Clicking the new status bar panel also allows you to conveniently change it or re-open the file in a different encoding. – Immo Landwerth Dec 22 '13 at 23:45
  • 5
    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. – fregante Dec 30 '14 at 12:48
  • 2
    @bfred.it: Yes, as described in [Gregordy's answer](http://stackoverflow.com/a/27596642/45375), but it's important to note that the information only shows for about _4 seconds_. – mklement0 Dec 24 '15 at 03:51
  • 10
    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,`. – not2qubit May 30 '18 at 12:00
  • 3
    Why isn't this enabled by default... +1 – Daniel Lidström Apr 16 '20 at 11:08
  • 1
    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. – MiB Aug 21 '21 at 10:55
323

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())
Hugo Corrá
  • 14,546
  • 3
  • 27
  • 39
  • 4
    @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. – Hugo Corrá Oct 17 '13 at 16:30
  • 4
    Yes, but it only happens with particular files. I think if the file doesn't have a defined encoding maybe. – calumbrodie Oct 17 '13 at 17:34
  • While calling view.encoding() I got `UTF-8` but while calling `print sys.stdin.encoding` from Python I got `None` – andilabs Dec 03 '13 at 15:04
  • @calumbrodie You can try my solution mate, much quicker in my sense ; ) – Gregordy Jul 18 '15 at 08:09
  • 3
    `'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). – mklement0 Dec 24 '15 at 03:48
  • I would ask how can I "_create an shortcut that executes the following command: `sublime.message_dialog(view.encoding())`_" as suggested by Hugo. Thanks – sporak Aug 22 '18 at 15:17
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

Rodrigo Gauzmanf
  • 2,517
  • 1
  • 23
  • 26
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.

Gregordy
  • 597
  • 7
  • 18
  • 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. – MiB Aug 21 '21 at 10:58
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.

Bogdan Calmac
  • 7,993
  • 6
  • 51
  • 64
1

plugin ConverToUTF8 also has the functionality.

Honghe.Wu
  • 5,899
  • 6
  • 36
  • 47