DervishD wrote:
    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 :(((

No need to frown: US-ASCII "is" UTF-8 (but the reciprocal is not always true): or if you prefer, a UTF-8 file containing only codepoints below U+0080 can be read correctly, with no errors or misreadings, by any program accepting US-ASCII.


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).

I think you can place upper-half characters anywhere. If there are _no_ upper-ascii characters anywhere in the file, then it's us-ascii and the above remark applies.


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 :(((

Yes, 'fileencodings' should contain at most one 8-bit encoding, and if there is one, it should be last, because 8-bit encodings never give a "fail" signal.


    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.

Rather than map ":w ++enc=latin1" I would map ":setlocal fenc=latin1", because with the latter (but not with the former) all saves of the file will be in latin1 until you ":quit" the file


    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


As long as your vimrc includes only 7-bit ASCII, there's no problem. But in the particular case of your vimrc, you could add the following lines at top, do ":setlocal fenc=latin1", and (IIUC) it will always be _read_ as Latin1 in the future, because of the accented letters in your name:

" Vim configuration file
" Maintainer:      Raúl Núñez de Arenas Coronado <[EMAIL PROTECTED]>
" Last change:     11-Jan-2007

(The "Last change" line is _not_ updated automagically.)


Best regards,
Tony.

Reply via email to