Hi Tony :)

 * A.J.Mechelynck <[EMAIL PROTECTED]> dixit:
> DervishD wrote:
> >    My system is latin-1, so I want my files written using latin-1
> >encoding. But sometimes I get files in utf8 encoding, so I set up my vim
> >like this:
> >
> >    set encoding =latin1
> >    set fileencoding =latin1
> >    set fileencodings =ucs-bom,utf-8,latin1
> >
> >    This last line is causing big problems to me. Everytime I edit one
> >of MY files, not the utf8 imported files, vim converts it to utf-8,
> >because while ucs-bom may fail as an encoding, utf-8 not.
> >
> >    My problem will be gone if I set "fileencodings" to just latin1, but
> >then I won't get utf-8 files automagically converted and presented to me
> >in a readable form.
> >
> >    Is there any way to get what I want, that is, to have ALL my files
> >edited as latin1 but convert utf-8 files properly without using the
> >"++enc" thing?
> 
> Your problem lies in the relation between UTF-8, Latin1 and US-ASCII. 
> Characters 0x00 to 0x7F are represented identically in all three, therefore 
> if a file contains only 7-bit ASCII characters, it won't make any 
> difference whether it is interpreted as US-ASCII, Latin1 or UTF-8 -- the 
> data will be the same, *represented the same way*, in all three cases.

    I know that, ucs-bom and utf-8 are tried before latin1 and utf-8
always succeeds for US-ASCII files :(((

> You can do it in advance by intentionally placing some upper-ASCII in the 
> file, for instance by underlining the top title with 
> ÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ (a line of "divide-by" signs, 0xF7), then saving 
> the file as Latin1.

    Yes, I thought about that solution, but it's messy and not always
applicable (I cannot place upper latin1 characters in some files at the
beginning, or remember to save it as latin1).

> Note that in order to edit Unicode files properly, it is more prudent to 
> set 'encoding' to UTF-8, otherwise if you happen to edit a file containing 
> anything which your current 'encoding' cannot represent, it will get 
> garbled, and Vim won't be able to restore the original value when saving 
> the file. You can do it as follows (in your vimrc):
> 
>       if &encoding !~? "^u"
>               if &termencoding == ""
>                       let &termencoding = &encoding
>               endif
>               set encoding=utf-8 fileencodings=ucs-bom,utf-8,latin1
>               setglobal bomb fileencoding=latin1
>       endif

    So, there is no way of solving my problem unless I put "latin1"
before "utf8" in "fileencodings", but then nothing will work because
"latin1" will always succeed :(((

    A partial solution for me would be to force "latin1" when saving a
file, but then I take the risk of messing the encoding of a couple of
projects where I may add code which are utf-8 :((

    Probably my best bet is to map "save as latin1" and do this
manually.

    BTW, and regarding your suggestion above, I just forgot to do it
back when I wrote my vimrc while reading the documentation. I missed the
prominent note, sorry O:))))

    Thanks for your help :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!

Reply via email to