How to change the Sublime Text encoding
"Learn how to change encoding in Sublime Text with an easy-to-follow example: File > Save with Encoding > UTF-8".
Changing the Sublime Text Encoding
To change the encoding of a file in Sublime Text, open the file in the editor. Then, open the Command Palette by pressing the keyboard shortcut Ctrl + Shift + P (or Command + Shift + P on Mac).
In the Command Palette, type “Set Encoding” and select the “Set Encoding: UTF-8” option. This will change the encoding of the file to UTF-8.
If the file is already encoded in UTF-8, you can select the “Set Encoding: Western (Windows 1252)” option to change it to the Windows 1252 encoding. This will ensure that the file is readable by Windows-based programs.
You can also set the encoding of the file to any of the other encoding options available in the “Set Encoding” list. To do this, select the “Set Encoding” option in the Command Palette, and then select the encoding that you want to use.
Once you have set the encoding of the file, you can save it by pressing the keyboard shortcut Ctrl + S (or Command + S on Mac).
const encoding = 'utf-8';
// set encoding of the file
if (file.encoding !== encoding) {
file.setEncoding(encoding);
}
Once the encoding has been changed, the file will be displayed correctly in Sublime Text and any other programs that support the encoding.