Sublime Forum

Save file encoding in helper file


Hi to everyone,

I have been using Sublime Text for very long time and this is my first post in this forum. I was considering switching to VS Code because of problem that I have, but for now I will continue using ST just because I used to it. :slight_smile:

Recently, I was using ST to write some PHP and HTML code to display data from old Informix database and text in that database is encoded with Windows-1250 encoding. I had trouble of how to correctly display this text I found out that I have two options:

  1. to convert all text to UTF-8 after reading it from DB, and use UTF-8 encoding for PHP and HTML pages
  2. to save all my PHP and HTML pages with Windows-1250 encoding (and put the same encoding in HTML head tag of course)

I choose option 2 and it is working mostly fine. Both static text (headings and titles) on my page and from DB are displayed correctly.
But now I have a problem when I need to edit those pages. I double click on file in Windows Explorer (or drag file/folder to ST window or icon) then file opens in ST, then I change something in code and when I try to save the file I got error that not all characters are valid Windows-1250 encoding and that ST is falling back to UTF-8. This means that when I opened file ST didn’t recognize that file encoding was Windows-1250 so it opens a file as UTF-8 and some original characters are replaced with weird characters that are not from my languages, for example: from Č to È, but È can’t be encoded in Windows-1250 encoding and then I must find all of those weird characters and manually convert them back to valid characters from my language (Serbian).
I know that it is hard for ST to correctly detect file encoding just from content but can someone write a plugin, or is there already a plugin, that creates additional helper files along side original file, and in that helper file could information what is encoding for base file.
Then when I save file with some non standard encoding ST will create this helper file and when I later open that file again it will consult that helper file to know what is correct encoding for content in base file is and it will open file with correct encoding, and I will not have a problems when saving file.
Of course, if helper file is missing in current dir for base file that is opening ST will use default encoding.

In my work I have mixed encodings in files but most of them are in UTF-8 that are working fine but other encoding are giving me a headache, so I will be grateful for some help.



did you consider just setting your "fallback_encoding" preference in ST to "Central European (Windows 1250)"?