Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I set my prefs to save files in UTF-8 (the default). But I've noticed that my files are not UTF-8 but US-ASCII.

With my newly created file:

file -I myfile

=> myfile: text/plain; charset=us-ascii

What gives?

share|improve this question
add comment

migrated from stackoverflow.com Jul 13 '11 at 17:00

This question came from our site for professional and enthusiast programmers.

1 Answer

I'm not an expert in the field, but I believe the reason for this is you probably saved your test file only with ASCII characters. When using only ASCII characters UTF-8 is simply indistinguishable from it. It's when you start using characters that are outside ASCII scope (e.g. accents in other languages, like ąśćż in polish) the difference is noticable.

Try copy&paste the characters I used as an example, save your file again and test it.

share|improve this answer
    
You're right, once I included some non-ascii chars, TextMate saved it as UTF-8. Thanks! –  user7801 Jul 14 '11 at 1:53
    
@Plenilune: If @Michal M's answer worked for you, then please accept it so he gets the credit. –  Philip Regan Jul 14 '11 at 2:23
    
I'm having exactly the same issue. I think the main issue is that TextMate is saving the file in ASCII, but it should save the file in UTF-8 (even with just ASCII chars in it). And I'm sorry but what exactly is your answer here? Write none-ASCII chars in every file so that TextMate will write the file as UTF-8? –  hade Oct 5 '11 at 7:30
    
No, you don't have to put non-ASCII chars in order for the file to be saved in UTF-8. The answer is - if the file has no non-ASCII chars it is indistinguishable from ASCII, hence it can be recognised as an ASCII encoded file even though it was saved as UTF-8. –  Michal M Oct 5 '11 at 8:53
    
Thanks for the clarification. Few things more. I've done lately some coding with Ruby 1.9.2 and it's quite strict when it comes to encodings. So my files need to be exactly as UTF-8. I have set up TextMate to save my files in UTF-8. If I write only ASCII chars and save => "file myfile" will give me ASCII. And once I write none-ASCII chars and save => "file myfile" will give me UTF-8. So this is the problem. I need all my files to be saved as UTF-8, regardless of the content. I hope you understood me ;) –  hade Oct 5 '11 at 9:28
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.