178

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"
Gama11
  • 28,518
  • 9
  • 66
  • 91
Fernando Tholl
  • 2,277
  • 2
  • 14
  • 12

3 Answers3

332

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.

DarkNeuron
  • 7,000
  • 2
  • 40
  • 46
  • 10
    "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" – Gerfried Jun 21 '17 at 07:33
  • @Gerfried "If you want UTF8 files with BOM, the setting is `"files.encoding": "utf8bom"`" - it doesn't work. See https://github.com/Microsoft/vscode/issues/47089 – john c. j. Apr 04 '18 at 21:11
  • 8
    please avoid using utf8bom, you not need it – sherpya Jun 05 '18 at 14:57
  • 2
    @sherpya except when (for some annoying program) you do... -.- – RaptorX Jun 29 '21 at 23:00
  • @sherpya I agree. Yet sometimes you do, for example to make the Delphi compiler recognize your UTF-8 files ‍♂️ – Marcus Mangelsdorf Mar 11 '22 at 16:36
  • 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. – MyNameIsTrez Mar 15 '22 at 18:48
36

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.

user692942
  • 15,667
  • 7
  • 74
  • 164
JotaBe
  • 36,481
  • 7
  • 93
  • 114
  • 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 – Rafael Hernández Marrero Dec 18 '21 at 14:32
2

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.

Sven Eschlbeck
  • 772
  • 5
  • 26