Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

discussão

If I :wq it everything is ok.

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

discussão

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Use

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.

share|improve this answer
    
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. –  Tiago_ May 25 '13 at 16:30

Your Answer

 
discard

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

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