0

In the ruby file:

p __ENCODING__

#<Encoding:US-ASCII>

In vim:

set encoding?
encoding=utf-8

This is causing me grief (http://stackoverflow.com/questions/14495486/ruby-syntax-error-with-multiple-language-in-hash), which is patched but I still don't understand why the file shows as ASCII by ruby and utf-8 by vim.

pixelearth
  • 13,674
  • 10
  • 62
  • 110

1 Answers1

2

As @melpomene commented, :set encoding tells you what encoding is used internally by Vim.

:set fileencoding will tell you what encoding Vim decided to use for your document. The possible values are given by the fileencodings option. ASCII is not part of the default list as it's usually handled transparently by the other encodings listed.

But that part of your question is puzzling me:

but I still don't understand why the file is ASCII

because it looks like you actively want that file to be treated as ASCII by the interpreter.

Anyway, that encoding directive is only used by Ruby: it doesn't mean that the file is actually encoded as ASCII or that Vim is supposed to care about it and treat it in a special way.

In short, whether your file is actually encoded in ASCII or not, Vim doesn't care.

So… what do you want exactly? That vim sets its fileencoding option to ASCII when you open a supposedly ASCII file? That your supposedly ASCII file be converted to another encoding?

edit

  1. With that directive, you explicitely tell Ruby that the file's content must be treated as ASCII and Ruby says "OK, that's ASCII, if you say so.".

  2. This directive doesn't change anything to the actual encoding of the file. It could be utf-8, latin1 or whatever.

  3. Vim doesn't understand that directive.

  4. Vim chooses the encoding it uses for that file according to a number of rules you should read about in :h encoding, :h fileencoding and :h fileencodings.

  5. Vim doesn't treat ASCII in a special "ASCII" way, it just handles it has the subset of utf-8 that it is.

So, before we go further, please verify:

  • the encoding of the file with something like $ file /path/to/file

  • the fileencoding Vim uses for that file with :set fileencoding

romainl
  • 186,200
  • 21
  • 280
  • 313