Search code examples
visual-studio-codeencodingarabic

How to fix VS Code encoding


I have many files containing Arabic characters. When I open it on any editor it does not show properly. I fixed the problem through Windows settings, and then I tried opening it with bloc note and it worked properly.

Since Vscode is way better for editing, I tried to open the files there, but the Arabic characters are not showing properly.

In the bottom right corner, I pressed ISO 8859-2 > reopen with encoding > Arabic (windows 1256), and the problem was fixed.

I tried to save with encoding but closing and opening the same file, apparently restored the default settings.

In the VScode settings, i did this: "files.autoGuessEncoding":true Also, I changed the user and workspace default encoding to Windows 1256 and I checked the box of try to guess the encoding ...

I closed vs code and reopened it, opened the folder, but the files are not showing as they should be. I checked the settings and it is like I left them (windows 1256)


Solution

  • Create a .vscode Folder:

    • Open your workspace directory where your project files are located.
    • Create a new folder named .vscode. This folder will store VS Code settings specific to your project.

    Create a settings.json File:

    • Inside the .vscode folder, create a new file named settings.json.
    • This file will contain the VS Code settings that override the default settings for your project.

    Specify Encoding Settings:

    • Open the settings.json file in a text editor.
    • Add the following content to the file:
         {
           "files.autoGuessEncoding": false,
           "files.encoding": "windows1256"
         }
    

    This configuration explicitly sets the encoding to "windows1256" for all files within your project folder and its subfolders.

    Save the File:

    • Save the settings.json file.

    Test the Configuration:

    • Open VS Code and navigate to your project folder.
    • Open a file containing Arabic text that was previously displaying incorrectly.

    The Arabic text should now display correctly with the specified encoding "windows1256".