How to convert plain text from code page Windows 1250 to code page ISO 8859-2?

1,793 views
Skip to first unread message

Igor Forca

unread,
Apr 8, 2015, 11:31:49 AM4/8/15
to vim...@googlegroups.com
VIM 7.4 ON UBUNTU 14.04

1. Open Vim with command:
vim

2. Set internal Vim encoding to UTF-8:
:set encoding=utf-8

3. Open file that is encoded using Windows 1250 code page:
:e ++enc=cp1250 test.txt
Note: In status bar there is message: [converted]

4. Change file encoding to ISO 8859-2 code page:
:set fileencoding=iso-8859-2

5. Save the file and actually do the code page conversion:
:w
Note: In status bar there is message: [converted] written

Above steps works perfectly without a problem. But this is on Vim for Ubuntu.


Now a problem.


gVIM 7.4 ON WINDOWS 7

All steps the same as above. But at step 5 when I try to save a file I get an error:
"test.txt" E213: Cannot convert (add! to write without conversion).
See print-screen of error message: https://i.imgur.com/ZuVRpOK.png
See print-screen of gVim for Windows version: https://i.imgur.com/uWNE8ce.png

Any idea what is wrong on my Vim for Windows?

Ben Fritz

unread,
Apr 8, 2015, 2:58:14 PM4/8/15
to vim...@googlegroups.com
Windows encoding names are weird.

According to Wikipedia (https://en.wikipedia.org/wiki/ISO/IEC_8859-2) Windows' codepage 28592 is equivalent to ISO-8859-2/Latin2.

So, try setting fenc to cp28592 when you're in Windows, rather than the canonical name.

Igor Forca

unread,
Apr 9, 2015, 8:03:53 AM4/9/15
to vim...@googlegroups.com
Ben,

For step 4:
:set fileencoding=cp28592
solves the problem.

It is little bit strange to me that iso-8859-2 has to be written as cp28592 in Vim, but on the other hand "utf-8" is perfectly valid code page name in Vim. I would expect consistency in this case UTF-8 code page written as cp65001 and so not excepting "utf-8" name - see Windows code pages: https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx

But I would prefer to have the same names on both Vim for Linux and Vim for Windows. I have some vimscripts and as I see I will have to have two scripts one for each operating system, I an not very happy about this.

Thanks a lot.

Ben Fritz

unread,
Apr 9, 2015, 10:53:16 AM4/9/15
to vim...@googlegroups.com
You can still share a script. First, you could try the cp28592 encoding on Linux, possibly with the "8bit" prefix, i.e. "8bit-cp28592".

If that doesn't work or you don't like it, you can determine the OS in your script:

if has('win32')
setl fenc=cp28592
else
setl fenc=iso-8859-2
endif

Finally, I think the reason the ISO-8859 name doesn't work, is that Vim on Linux is using the iconv library to do the conversion, and on Windows it is using Windows built-ins for the conversion, which accept codepage names instead.

I think it is possible to get Vim on Windows to use an iconv.dll library. I'm not sure exactly how it will work, but if you do that you could probably use the canonical name. See :help iconv-dynamic. You'll need to find an iconv library compiled for Windows.
Reply all
Reply to author
Forward
0 new messages