'Set encoding permanently in Visual Studio Code

I am using Visual Studio Code to write a LaTeX file with the LaTeX Workspace plugin.

However everytime that I open VS Code it insists that the encoding of the TeX file is UTF-8 and makes all the special characters go bezerk, but for some reason TeX Live doesn't compile in that encoding even if I convert it. Since another person is using the file too and their editor is set in Windows 1252 encoding, I want to keep using that.

How to set a encoding to a file permantly (or to an extension) in VS Code?



Solution 1:[1]

There are language-specific configurations. CTRL-Shift-P and see "Preferences: Configure Language Specific Settings... However, I do not see a LaTex choice there. But you may because of the LaText Plugin. So you could do something like:

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

If you don't see one perhaps you could associate your file extension (.tex?) with one on the list and then the above setting?

I assume you have

{
  "files.autoGuessEncoding": false
}

already set to false - the default. WTH, try "true".

And see Allow to set files.encoding as language specific setting for files on startup so the lanuage-specific setting should work better on start-up.

Solution 2:[2]

Your settings.json per user or per workspace can contain an encoding directive.

If you want Java files opened in UTF-8, then the following has no effect

"files.encoding" : "utf8",

but this works

"[java]": {
    "files.encoding": "utf8"
}

Solution 3:[3]

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.

Solution 4:[4]

Having autoGuessEncoding true in USER and autoGuessEncoding false, "files.encoding": "windows1250" in WorkSpace was still giving me windows1252.

I do not uderstand why User overchanged WorkSpace. I have to disable autoGuessEncoding also in USER to finally get "files.encoding": "windows1250" work everytime.

So you can face the same issue and this could help.

Solution 5:[5]

VSCode set default file encoding

Sven Eschlbeck's answer illustrated:

File -> Preferences -> Settings

The following page will be opened. There are many settings. To get to the desired item without scrolling through all entries, type "Encod" in the search box. Observe that the item "Files: Encoding" is presented to us. Now we can change the setting.

Use search box to get to the item quickly

Tips to share with you: "GB18030" applies fairly well universally for source code files containing Chinese characters.

More tips:

The encoding being applied to the current file is shown in the status bar. Mouse right-click this to call up the options as shown.

Quick access to change character encoding

Here, you can switch encoding ad-hoc.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Peter Buchmann
Solution 3 Sven Eschlbeck
Solution 4 Lud?k Holoubek
Solution 5