Last updated: Apr 6, 2024
Reading time·3 min
To change your encoding for a specific file in VS Code:
UTF-8
label in the bottom status bar.Here is a short clip that demonstrates the entire process.
You can also use the search field to search for a specific encoding.
If you need to change the file encoding globally:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
Once you click on the Files: Encoding setting, you can pick an encoding from the dropdown menu.
Setting the encoding globally only applies to newly created files.
settings.json
fileYou can also set the file encoding globally in your settings.json file:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json.
Click on Preferences: Open User Settings (JSON)
"files.encoding": "utf8",
Note that there is also a File: Auto Guess Encoding setting.
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
When the setting is enabled, VS Code attempts to guess the character encoding when opening files.
You can check the checkbox if want to test out the auto-guess encoding feature.
The feature has gotten much better over time.
Auto-guessing the file encoding is disabled by default.
If you need to set the encoding for a specific language(s):
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json.
Click on Preferences: Open User Settings (JSON)
"[language-identifier]": { "files.encoding": "utf8" },
For example, the following 3 lines set the PowerShell encoding to utf8
.
"[powershell]": { "files.encoding": "utf8" },
You can view all language identifiers in this table in the official docs.
I've also written an article on how to change the indentation in VS Code (2 or 4 spaces, Tab size).
You can learn more about the related topics by checking out the following tutorials: