DervishD wrote:
    Hi all :)

    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?

    Thanks a lot in advance :))

    Raúl Núñez de Arenas Coronado


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.

If you want Vim to explicitly see a file as Latin 1 with the 'fileencodings' above, it must contain some character(s) in the range 0x80-0xFF, because otherwise it won't contain anything which is "invalid" as UTF-8. That doesn't create any problem as long as there is only 7-bit data in the file because Latin1 and UTF-8 are both supersets of US-ASCII and represent all 128 US-ASCII characters the same way; the first time you type something above 0x7F, _then_ you should make sure to use ":setlocal fileencoding=latin1".

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.

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

Best regards,
Tony.

Reply via email to