1

I've searched a lot about this on Internet but nothing's working.

I'm using Vim 8.0.3 on Windows 10 and I can't get the right encoding to work. It's not a problem when writing code, but the problem comes when I try to write some text, mostly because I normally use Spanish and some characters are changed for other symbols. Here's an screenshot:

enter image description here

I don't think the problem is because I'm using Cmder, because in CMD and Powershell I have the same problem. Maybe any of you have the solution to this.

  • 2
    What do you mean by not working ? encoding is it set to utf8 (set encoding) ? – fievel Oct 26 '17 at 5:18
  • try set encoding=utf-8 in the vimrc file – ntohl Oct 26 '17 at 9:01
3

Windows doesn't use UTF-8 natively. It uses UTF-16LE by default. If you do not change the Windows console to UTF-8, it is not going to do what you want with the text.

Part of the problem may be that you aren't using Windows console, at least not directly: your screenshot shows you're using a third-party tool called Cmder, which may be part of the problem. It is possible that the UTF-8 solution linked above will fix Cmder, too, but if not, try running Vim via cmd.exe instead.

If that fixes it, you might want to switch to the Cygwin build of Vim, since Cygwin normally uses MinTTY, a considerably nicer console program than the stock Windows one. Because Cygwin is trying to emulate Linux atop Windows, it uses UTF-8 by default.

2

GENERAL SETTINGS

Vim internal use of encoding (this settings is must if you like to use utf-8 or you would like to convert encoding from one to another). I strongly recommend to set this setting in _vimrc file (Windows equivalent of Linux .vimrc file). You can open your _vimrc file with command: :e $MYVIMRC

:set encoding=utf-8

Bellow is actual setting that will convert to utf-8 when you execute :w (saving file). You can also set this in _vimrc file.

:set fileencoding=utf-8

There is also smart to set encodings (notice "s" at the end of command). Bellow settings tries to recognize the encoding of existing file when file is opened. I also suggest to save this setting in _vimrc file.

:set fileencodings=ucs-bom,utf8,latin1

SAMPLE HOW TO CONVERT FILE ENCODING FROM ONE ENCODING TO ANOTHER

Now lets say you have a file in some other encoding like cp1250 (latin2) and you would like to convert encoding to utf-8.

  1. Set internal Vim encoding to utf-8. A must have setting if multiple code pages are used and converting between them.

    :set encoding=utf-8

  2. Open file and let Vim know what is your current encoding file is saved in (e.g. cp1250 for Eastern Europe encodings = latin2)

    :e ++enc=cp1250 YourFile.txt

or if file already opened: :e! ++enc=cp1250

  1. Set target file encoding to utf-8:

    :set fileencoding=utf-8

  2. Now do actual save (conversion happens now):

:w

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.