Search code examples
encodingvisual-studio-code

How to setup Visual Studio Code to detect and set the correct encoding on file open


I recently started to use Visual Studio Code on server systems where I did not have Studio IDE installed. I like it very much but I'm running into a problem.

When I open a file (used Notepad++ before) the editor detects the encoding and sets it for me. I have many files on Windows servers that are still with windows-1252 but VS Code just uses UTF-8 by default.

I know I can reopen with encoding Western (Windows 1252) but I often forget it and I have sometimes destroyed some content while saving it.

So I did not find any parameter yet, is there a way to make VS Code detect the encoding and set it automatically when I open a file?


Solution

  • To allow Visual Studio Code to automatically detect the encoding of a file, you can set "files.autoGuessEncoding":true (in the settings.json configuration file).

    https://github.com/Microsoft/vscode/pull/21416

    This obviously requires an updated verison of the application compared to when the question was originally asked.