From the comment questions, even though the question states "encoding is set to utf-8", it appears Vim's encoding is NOT set to utf-8. It is still latin1 (ISO-8859-1). This means Vim does not know how to represent those special characters in memory, nor save them to a file.
For Vim to correctly write "special" characters, it needs 2 things:
- An 'encoding' setting that can represent that character in memory, usually utf-8
- An empty value, or a setting that can represent that character on-disk for 'fileencoding'. Usually this is also utf-8, or empty.
To properly read a file containing these characters, Vim again needs these two things. Vim can automatically detect the proper value for 'fileencoding', if your 'fileencodings' option is set properly.
'fileencodings' is a comma-separated list that tells Vim (in order) which encodings to try. "ucs-bom" as in the comments on your question will detect unicode, but only if there is a BOM (byte-order mark). Additionally since your Vim's 'encoding' is still "latin1" it wouldn't do you any good anyway if Vim DID detect unicode.
Note both 'encoding' and 'fileencodings' should be very close to the top of your .vimrc, before ANY mappings, menus, string options, or register settings. Otherwise existing text in those areas will be misinterpreted by Vim.
See the help for each of these options, and the wiki page on configuring Vim for Unicode, for details.
If Vim does't detect encoding properly on some files even with the correct settings, you can either:
- Set it manually, like
:e ++enc=utf-8 myfile.txt
- Install a Vim plugin that will automatically detect file encoding
'fileencodings'
,'fileencoding'
,'encoding'
?