Atom editor – how to select file encoding by file extension

This is going to be a rather short article. Just a quick guide, step by step on how to configure Atom to choose a different default encoding depending on file extension.

Here’s the problem: Atom defaults to UTF8, and we all love it, but there are always ancient projects that must be coded in other legacy encodings. Being my favorite editor for the last year I really want to use it for everything, but for those projects having to choose the encoding each time is a pain, and a source of data corruption.

Atom itself doesn’t include any option to do this, neither by folder, project or file extension. In my case, file extension is the preferred way.

There’s a package to do this, but the description is rather short and cryptic for new users:

For sometime I thought it doesn’t work but after careful reading of the following instructions I understood what needs to be done:

exactly! those are the instructions that require careful reading

So it needs a tiny bit of hacking as this package does not come with a UI to tweak. You have to change the atom config yourself. But it is really simple. Let’s go step by step.

First, open Atom preferences and install the package:

Now click on the “Open Config Folder” button on the lower left:

…just in case you’re wondering where’s the damn button

A new window will open. Remember to open the tree at the left by using the arrow or using the View Menu:

…just trying to be foolproof!

Now select “snippets.cson”:

This file is where you can add your custom hacks/configs into Atom without breaking anything internal

This file should look like this:

All you need to do here is add a few lines at the end:

For the sake of copy-pasting, here is in text version:

    defaultEncoding: "utf8"
    defaultEncoding: "iso8859-15"

Here is what this does:

For any extension (hence the “*”), use UTF8 for default encoding.

For a file which extension is “.my-file-extension”, use ISO8859-15. Change the extension to whatever you like, e.g. “.php”, “.cobol”, “.asm”.

Of course, you can add more blocks like this one to define more extensions. It’s not limited to just one.

And that’s all! Atom should read it straight away, but if it gives trouble, try to restart the editor to be sure.

Hope it’s useful to someone, as Google doesn’t show any results for any search terms I tried so far.

Finally, a friendly advice to Atom package creators: