How to force Notepad++ to open files only in UTF-8?
Asked Answered
H

1

7
  • I have a file with the following code: print "Hello World".

  • In Encoding section (Notepad++ Menu), Encode in UTF-8 is chosen.

  • I close the file, and open it again: nothing has been changed. Perfect.

  • I add some Unicode character, so the code now is: print "Hello World ๐Ÿ˜€".

  • I close the file, and open it again; I see: print "Hello World ั€ัŸะ‚".

  • In Encoding section, Encode in ANSI is chosen.

  • Once I forget to change it back to Encode in UTF-8, and start typing something, all Unicode characters are lost.

Any changes to Settings -> Preferences -> New Document -> Encoding as well as to // MISC. -> Autodetect character encoding change nothing for me.

Is there any way to force Notepad++ 7.3.2 to open all files in UTF-8?

Hathorn answered 20/2, 2017 at 8:48 Comment(3)
Good reproduction steps. I have the same behavior and the only way to prevent it was to save the file in UTF-8 with BOM. I think it is due to that particular emoji. If I put Chinese in the file it opens correctly. Seems to be a bug in Notepad++ UTF-8 detection. โ€“ Polito
If your toolchain barfs on a BOM, but not UTF-8 in a string literal or comment, you might try putting a BOM inside a comment at the start of the file. If UTF-8 with BOM just works, though, use that. โ€“ Berliner
As I see it, the problem starts with the files not being saved in the right encoding. For example, if I save a file in GB2312 (simplified chinese) and reopen the file, it will open in ANSII. I just have to change back the encoding manually and everything is ok. But if I save it in UTF-8, it will always open UTF-8. But I might be wrong. โ€“ Directorial
V
1

I can't reproduce your problem, maybe because of a newer version and a new setting "Apply to opened files":

enter image description here

Vitale answered 5/8, 2021 at 20:51 Comment(0)

© 2022 - 2024 โ€” McMap. All rights reserved.