My system locale is set to UTF-8:US, this is confirmed by running the locale command. But it is very strange that every time I type the vim FILENAME command (the file does not exist, I'm using this command to create a new file), and I use :wq to save the file, I always get file coded in ASCII. I tried to add the line set fileencodings=utf-8 in the .vimrc file, but nothing changed. How can I solve this ?
Asked
Active
Viewed 2,471 times
3
No No
- 31
- 2
2 Answers
3
When all your chars are < 128 ASCII and UTF-8 are the same.
ASCII is a subset of UTF-8 (and also a subset of latin1 and many other encoding formats).
Probably everything is perfect!
The configuration command:
set fileencodings=list of encoding formats to try
is used to define the order of encoding format that vim will try to use when opening a file.
set fileencodings=ucs-bom,utf-8,latin1 is a better idea: first try
to use any Unicode with a BOM header, then it will try to interpret it as UTF-8, and if everything fails latin1.
-
2I think this is correct, as I just created two files with `vim`, one containing a single `a` and one containing a random UTF-8 character; `file 1` outputs `1: ASCII text`, `file 2` outputs `2: UTF-8 Unicode text`. So it looks like the encoding is set based on the smallest character set containing the set of characters actually used. – kos Nov 02 '15 at 16:17
-
@kos, thank for the experiment. It makes sense. – Nov 02 '15 at 16:33