226

Is there any way to change the encoding of a file? For example UTF-8 to ISO 8859-1?

Setting Example Sublime Text:

"default_encoding": "UTF-8"

3 Answers 3

415

So here's how to do that:

In the bottom bar of VSCode, you'll see the label UTF-8. Click it. A popup opens. Click Save with encoding. You can now pick a new encoding for that file.

Alternatively, you can change the setting globally in Workspace/User settings using the setting "files.encoding": "utf8". If using the graphical settings page in VSCode, simply search for encoding. Do note however that this only applies to newly created files.

Sign up to request clarification or add additional context in comments.

8 Comments

"files.encoding":"utf8" will create files without BOM (which is mostly the better decision). If you want UTF8 files with BOM, the setting is "files.encoding": "utf8bom"
please avoid using utf8bom, you not need it
@sherpya except when (for some annoying program) you do... -.-
VS Code told me my file was encoded in UTF-8, but a program reading that file didn't agree with that assessment. I had to tell VS Code to save it with another encoding first, and save it back to the UTF-8 encoding afterwards for that other program to agree it was UTF-8.
@sherpya The popular Chocolatey package manager says "PowerShell scripts need to be saved in UTF-8 with BOM. PowerShell ... needs a BOM in order to recognize scripts as UTF-8." docs.chocolatey.org/en-us/create/…
|
51

Apart from the settings explained in the answer by @DarkNeuron:

"files.encoding": "any encoding"

you can also specify settings for a specific language like so:

"[language id]": {
  "files.encoding": "any encoding"
}

For example, I use this when I need to edit PowerShell files previously created with ISE (which are created in ANSI format):

"[powershell]": {
    "files.encoding": "windows1252"
}

You can get a list of identifiers of well-known languages here.

1 Comment

Hi, I tried to use this setting to change encoding for c files to cp850 (is the best one for Spanish language) but when I create a new file nothing changes, is always setting to utf-8 by default. I tried with different languages and encodings but it still putting the same encode
6

The existing answers show a possible solution for single files or file types. However, you can define the charset standard in VS Code by following this path:

File > Preferences > Settings > Encoding > Choose your option

This will define a character set as default. Besides that, you can always change the encoding in the lower right corner of the editor (blue symbol line) for the current project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.