Friday, October 7, 2011

Re: what's a "conversion error" and how do I correct it?

On 22/05/11 13:00, Christian Brabandt wrote:
> Hi eNG1Ne!
>
> On So, 22 Mai 2011, eNG1Ne wrote:
>
>> Working on a Linux box (Ubuntu 10.4), I've successfully copy/pasted a
>> block of text from a Planmaker spreadsheet into a vim file. The text
>> includes U+2012 dashes, which are correctly displayed in vim … but
>> when I try to save the vim file, I get the message "conversion error".
>
> I guess, your fileencodings setting (notice the plural) does not include
> utf-8, so Vim does not try to save it with that encoding. It probably
> either tries to save it using plain old ASCII encoding or something like
> latin1, which does not include this char and therefore conversion fails.
>
> You should fix your 'fencs' setting to something like
> ucs-bom,utf-8,default,latin1 or you can force Vim to save it in utf-8
> encoding, by issuing :w ++enc=utf8 filename. (It might be, that this
> needs the +multi_byte feature, which is only enabled, when compiling at
> least a big version of Vim).
>
>> Probably related, but when I used :dig to try and find the code for
>> the U+2012 dash (so I could use search/replace) I couldn't spot one.
>> Just out of curiosity, what do the numbers in the digraph reference
>> page refer to?
>
> The decimal number for that unicode char.
>
> regards,
> Christian
>

Conversely, when reading, Vim will not give a "conversion error" message
if there is an 8-bit encoding at the end of your 'fileencodings', but it
can still fail to recognize the actual encoding used: for instance, with
:set fencs=ucs-bom,utf-8,latin1 which is a "good" setting for people in
"Western" countries like I am, try to read a file containing Japanese
encoded in Shift-JIS, Traditional Chinese in Big5, Simplified Chinese in
GB18030, or even Russian in KOI8-R, and the text will look like
gibberish, because Vim saw no BOM, saw correctly that the text wasn't
UTF-8 on disk, and fell back on Latin1. In that case you need to tell
Vim the actual encoding of the file (and if you don't know it, maybe try
several possible ones, proceeding by trial and error), by adding a ++enc
modifier to your :e or :view command, for instance

:view ++enc=sjis example.txt

and (assuming that 'encoding' is already set to utf-8) Vim will then (if
compiled with +iconv, or with +iconv/dyn and the iconv or libiconv
library is available) happily translate the shift-JIS into the UTF-8
used internally.


About digraphs: 0x2012 == 8210 and I see no digraph for that, but you
could use Ctrl-V u 2012 (without the spaces, see :help i_CTRL-V_digit
which also applies in command-line mode) or make your own digraph (but
try to use something which is not already in use).


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
195. Your cat has its own home page.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment