Sublime Forum

Special encoding for certain file format (syntax)

#1

Hello!
I want my files in ‘.xxx’ format (with ‘xxx’ syntax and special folder for ‘xxx’ language) to be opened in certain encoding (Windows 866) each time, when I open it. But I dont want to change fallback encoding in global settings, because other project has UTF-8 encoding. Can I change encoding settings only for one file format or syntax?

0 Likes

#2

is it impossible?

0 Likes

#3

There’s probably a plugin to do something like this already, but I don’t know what it is. Anyways, you would probably use create an event listener and define an “on_load(view)” method. You can use “view.file_name()” to get the name of the file. From that you can parse the extension. You can then use “view.set_encoding(encoding)” to set the encoding for that particular view.

You could also create a syntax specific setting “Preferences -> Settings - More -> Syntax Specific - User”. Then create a “default_encoding” entry like you would normally. This should apply this encoding only for this syntax, leaving the default to whatever you currently have it as.

0 Likes

#4

I have used the second variant and now everything works as I want. Thanks a lot!

0 Likes