How to change the File Encoding in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
3 min

banner

# Table of Contents

  1. Change the File Encoding in Visual Studio Code
  2. Change the File Encoding globally in VS Code
  3. Setting the file encoding globally in your settings.json file
  4. Letting VS Code automatically guess the file encoding
  5. Setting the File encoding for specific Languages in VS Code

# Change the File Encoding in Visual Studio Code

To change your encoding for a specific file in VS Code:

  1. Click on the UTF-8 label in the bottom status bar.

click on utf 8 in bottom status bar

  1. A new pop-up window will appear with 2 options:
  • Reopen with Encoding
  • Save with Encoding
  1. Click on the Save with Encoding option.

click on save file with encoding

  1. Select your preferred encoding from the dropdown menu.

select your preferred encoding

Here is a short clip that demonstrates the entire process.

change file encoding

You can also use the search field to search for a specific encoding.

# Change the File Encoding globally in VS Code

If you need to change the file encoding globally:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings and select Preferences: Open User Settings.

open user settings

You can also open the settings screen by pressing Ctrl + , on Windows and Linux or Cmd + , on macOS.

  1. Type encoding and use dropdown menu of the Files: Encoding setting to change the encoding.

change encoding globally

Notice that you can change the encoding globally for the user or for the current workspace.

Once you click on the Files: Encoding setting, you can pick an encoding from the dropdown menu.

select global encoding

Setting the encoding globally only applies to newly created files.

# Setting the file encoding globally in your settings.json file

You can also set the file encoding globally in your settings.json file:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings json.

  2. Click on Preferences: Open User Settings (JSON)

preferences open user settings

  1. Use the following line to set the encoding globally.
settings.json
"files.encoding": "utf8",

set encoding globally in settings json

# Letting VS Code automatically guess the file encoding

Note that there is also a File: Auto Guess Encoding setting.

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings and select Preferences: Open User Settings.

open user settings

You can also open the settings screen by pressing Ctrl + , on Windows and Linux or Cmd + , on macOS.

  1. Type encoding and use dropdown menu of the Files: Encoding setting to change the encoding.

files auto guess encoding setting

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.

# Setting the File encoding for specific languages in VS Code

If you need to set the encoding for a specific language(s):

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings json.

  2. Click on Preferences: Open User Settings (JSON)

preferences open user settings

  1. Use the following syntax to set the encoding for a specific language.
settings.json
"[language-identifier]": { "files.encoding": "utf8" },

For example, the following 3 lines set the PowerShell encoding to utf8.

settings.json
"[powershell]": { "files.encoding": "utf8" },

You can view all language identifiers in this table in the official docs.

set encoding for specific language

I've also written an article on how to change the indentation in VS Code (2 or 4 spaces, Tab size).

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.