Sublime Forum

[Solved] How I make separate encoding for a particular extension or file?

#1

Description

I use AutoHotkey. I need saved .ahk files for AutoHotkey in UTF-8 with BOM encoding. By default UTF-8 for me. I wrote my .ahk file, FileSave with EncodingUTF-8 with BOM → file saved in UTF-8 with BOM. But if later I press Ctrl+S file is saved in UTF-8, and I need again FileSave with EncodingUTF-8 with BOM. I do debug my scripts, I often need to save files, and to make me FileSave with EncodingUTF-8 with BOM each time is inconvenient. I do not want change default encoding, because all the other files I saved in UTF-8.

Question

Can I saved .ahk files in UTF-8 with BOM, but other files in UTF-8? Or saved individual files in UTF-8 with BOM, when I press Ctrl+S?

Thanks.

0 Likes

#2

Define a syntax-specific setting with "default_encoding": "UTF-8 with BOM" for the ahk syntax. This will not apply if a file is saved with UTF-8 (without BOM) and contains non-ASCII characters. For these files, you’ll have to change the encoding manually like before.

2 Likes

#3

@FichteFoll, yes, my script contains non-ASCII characters (and therefore I needed to keep my script in the encoding UTF-8 with BOM) — cyrillic letters. Therefore, your method does not work: after Ctrl+S script is saved in UTF-8 :disappointed:. Do you know other methods to solve my problem?

Thanks.

0 Likes

#4

After you selected “File → Save with Encoding → UTF-8 with BOM” the file should continue to be saved as UTF-8 with BOM. That works for me.

1 Like

#5

@FichteFoll, I’m sorry, I forgot EditorConfig. In .editorconfig file of my project I added lines:

[*.ahk]
charset = utf-8-bom

And in UTF-8 with BOM now default encoding for my .ahk files.

Thanks.

0 Likes