I'm trying to edit UTF-8 text files using vim (7.3) on windows (prompt/powershell).

My _vimrc file is pretty simple:

set encoding=latin-1
set fileencoding=utf-8

The problem is, when editing a file that already exists, it (aparently) works. But If I use vim to create a new file, it doesn't write the same contents.

Let's say, I open a file using vim myfile.txt, that have this content:


If I :wq it everything is ok.

Now, if instead I'm creating a new file, after saving and reopening I get:


If I edit it to look like the first and save it, I can edit the file any number of times without problems.



set encoding=utf-8

and read :help 'encoding'.

In short, this option defines how Vim is going to treat text internally. It is usually set automatically by Vim to match your system's locale. If it can't get that information (or if your locale is latin1), Vim sets it to latin1 which, obviously, sucks hard.

Your best bet is to explicitly set it to utf-8.

On the other hand, set fileencoding=utf-8 is not needed and probably counterproductive because it is set by Vim for each buffer.

  • I tried that earlier and it didn't worked, but now for some reason I found my prompt was set to use code page 1252 instead of the default (code page 850), I changed that and it worked the way you suggested, thanks. – a34534 May 25 '13 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.