Change the encoding of a file in Visual Studio Code

Visual Studio-CodeCharacter EncodingVscode Settings

Visual Studio-Code Problem Overview


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"

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

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.

Solution 2 - Visual Studio-Code

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.

Solution 3 - Visual Studio-Code

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFernando ThollView Question on Stackoverflow
Solution 1 - Visual Studio-CodeDarkNeuronView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeJotaBeView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeSven EschlbeckView Answer on Stackoverflow