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

73,087

Solution 1

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.

Solution 2

  • Go to File-> Preferences -> User Settings
  • Add (or update) the entry "files.encoding": "windows1252" to the right editor window and save

Now VSCode opens all text files using windows-1252 when there is no proper encoding information set.

EDIT: In 2017's June release the files.autoGuessEncoding setting was introduced. When enabled it will guess the file's encoding as good as possible. Its default value is false .

Solution 3

Add guide by image :

File >> Preferences >> Settings

File >> Preferences >> Settings

Enter autoGuessEncoding and make sure checkbox is checked

Enter autoGuessEncoding

Solution 4

beware, auto guessing in vscode still does not work as expected, the guessing, is VERY inaccurate, and does still open as guessed encoding, even when the guess library returns also the confidence score being low - they use jschardet (https://www.npmjs.com/package/jschardet)

if the score of guess is not close to 100%, it simply should rather open in "files.encoding" instead of guessed encoding, but that does not happen, vscode authors should make better use of the confidence score jschardet returns

i open either utf-8 which guesses ok, and second encoding i use is windows-1250, which in 99% cases detects wrong as some other windows-... encoding or even iso-8859-... and such... cry daily at the computer having to experience this

tuning up the confidence checking and fallback to default encoding would do, it needs someone skilled to check their source and offer them a fix

Share:
73,087
YvesR
Author by

YvesR

I am a generalist instead of a specialist. Try to workout in many projects and often have contact with many different technology. Beside my work I have 2 kids, so nothing more to say about hobbies until they are grown up :) #SOreadytohelp

Updated on September 29, 2021

Comments

  • YvesR
    YvesR over 2 years

    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 vscode 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 vscode detect the encoding and set it automatically when I open a file?