Loading ...
Sorry, an error occurred while loading the content.

How to edit UTF-8 files with gVim on WinXP when "encoding=cp1250" ?

Expand Messages
  • tommm0
    Hi all, does anybody know how to edit UTF-8 files with gvim when encoding is set to cp1250 ? I use gvim on WinXP. Simple :e doesn t convert an utf-8 file to
    Message 1 of 5 , Aug 1, 2007
    • 0 Attachment
      Hi all,

      does anybody know how to edit UTF-8 files with gvim when encoding is
      set to "cp1250"?
      I use gvim on WinXP. Simple :e doesn't convert an utf-8 file to cp1250
      encoding. Even with
      iconv.dll in gvim directory.
      I also tried to set encoding to "utf-8" and edit the utf-8 file, but
      that led to some font problem:
      I got "Zaéiatok" instead of "Začiatok" in status line (slovak
      equivalent to ' Top ' in statusline)
      Any ideas how to do get everything displayed correctly? Thanks.

      Tom


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... You can t. But see at bottom. ... To be able to edit UTF-8 files, paste the following near the top of your vimrc. (You will still be able to edit cp1250
      Message 2 of 5 , Aug 1, 2007
      • 0 Attachment
        tommm0 wrote:
        > Hi all,
        >
        > does anybody know how to edit UTF-8 files with gvim when encoding is
        > set to "cp1250"?

        You can't. But see at bottom.

        > I use gvim on WinXP. Simple :e doesn't convert an utf-8 file to cp1250
        > encoding. Even with
        > iconv.dll in gvim directory.
        > I also tried to set encoding to "utf-8" and edit the utf-8 file, but
        > that led to some font problem:
        > I got "Zaéiatok" instead of "Začiatok" in status line (slovak
        > equivalent to ' Top ' in statusline)
        > Any ideas how to do get everything displayed correctly? Thanks.
        >
        > Tom

        To be able to edit UTF-8 files, paste the following near the top of your
        vimrc. (You will still be able to edit cp1250 files.) I'm not sure whether
        this code snippet should come before or after "source
        $VIMRUNTIME/vimrc_example.vim" (or, if you don't use that, "filetype [plugin]
        [indent] on" (where [] mark optional parts) -- i.e., before or after creating
        the menus. If the menus get corrupt, move them to the other side of this code.

        -- Also, make sure you're using a "recent enough" version, I remember there
        have been patches for corrupt menu display, even though I can't find back at
        which exact version and patchlevel it was done.




        " To edit UTF-8 files, we must set the -global- 'encoding' to UTF-8
        " first, save the locale encoding
        let g:locale_encoding = &encoding
        " give an error if the capability is not compiled-in
        if ! has('multi_byte')
        echoerr 'Error: +multi_byte not compiled-in !!!'
        else
        " if it's already Unicode, no need to change
        if &encoding !~? '^u'
        " give a warning in the console
        if ! has('gui_running')
        echomsg "WARNING: Trying to change 'encoding' in the"
        echomsg "console -- the display will probably get"
        echomsg "corrupted if we edit UTF-8 files with"
        echomsg "truly 'foreign' characters"
        endif
        " avoid clobbering the keyboard encoding
        if &termencoding == ''
        let &termencoding = g:locale_encoding
        endif
        set encoding=utf-8
        endif
        " define the heuristics to recognise file encodings
        set fileencodings=ucs-bom,utf-8,default
        " create Unicode files with B.O.M. by default
        setglobal bomb
        endif
        " create files in the locale encoding by default
        let &g:fileencoding = g:locale_encoding





        For explanations, use the Vim help ;-) about commands and options found above,
        and also ":help mbyte.txt" and in particular ":help UTF-8".


        Best regards,
        Tony.
        --
        There is a theory which states that if ever anyone discovers exactly
        what the Universe is for and why it is here, it will instantly
        disappear and be replaced by something even more bizarre and
        inexplicable. There is another theory which states that this has
        already happened.
        -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Neil Bird
        Around about 01/08/07 13:32, tommm0 typed ... ... Further to the earlier answer, if you ve opened a file and aren t happy with the encoding vim s chosen,
        Message 3 of 5 , Aug 2, 2007
        • 0 Attachment
          Around about 01/08/07 13:32, tommm0 typed ...
          > does anybody know how to edit UTF-8 files with gvim when encoding is
          > set to "cp1250"?

          Further to the earlier answer, if you've opened a file and aren't happy
          with the encoding vim's chosen, reopen it (can open it from new the same
          way, not sure of the command line variant) with ++enc:

          :e ++enc=utf-8

          --
          [neil@fnx ~]# rm -f .signature
          [neil@fnx ~]# ls -l .signature
          ls: .signature: No such file or directory
          [neil@fnx ~]# exit

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Tony Mechelynck
          ... However, you can only successfully set a fileencoding compatible with the encoding Vim uses to represent the data internally. If encoding is set to
          Message 4 of 5 , Aug 2, 2007
          • 0 Attachment
            Neil Bird wrote:
            > Around about 01/08/07 13:32, tommm0 typed ...
            >> does anybody know how to edit UTF-8 files with gvim when encoding is
            >> set to "cp1250"?
            >
            > Further to the earlier answer, if you've opened a file and aren't happy
            > with the encoding vim's chosen, reopen it (can open it from new the same
            > way, not sure of the command line variant) with ++enc:
            >
            > :e ++enc=utf-8
            >

            However, you can only successfully set a 'fileencoding' compatible with the
            'encoding' Vim uses to represent the data internally. If 'encoding' is set to
            UTF-8, you can edit anything. But if 'encoding' is set to latin1 you cannot
            edit any Unicode file containing one or more codepoint above 255.


            Best regards,
            Tony.
            --
            -- Gifts for Men --

            Men are amused by almost any idiot thing -- that is why professional
            ice hockey is so popular -- so buying gifts for them is easy. But you
            should never buy them clothes. Men believe they already have all the
            clothes they will ever need, and new ones make them nervous. For
            example, your average man has 84 ties, but he wears, at most, only
            three of them. He has learned, through humiliating trial and error,
            that if he wears any of the other 81 ties, his wife will probably laugh
            at him ("You're not going to wear THAT tie with that suit, are you?").
            So he has narrowed it down to three safe ties, and has gone several
            years without being laughed at. If you give him a new tie, he will
            pretend to like it, but deep inside he will hate you.

            If you want to give a man something practical, consider tires. More
            than once, I would have gladly traded all the gifts I got for a new set
            of tires.
            -- Dave Barry, "Christmas Shopping: A Survivor's Guide"

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • tommm0
            Thanks to both of you for help. But... The suggested solution doesn t work for my utf-8 file. Perhaps because it does not have any BOM. It gets better only
            Message 5 of 5 , Aug 2, 2007
            • 0 Attachment
              Thanks to both of you for help.

              But...

              The suggested solution doesn't work for my utf-8 file. Perhaps
              because it does not have any BOM. It gets better only when I
              set fileencodings to "ucs-bom,ucs-2le".

              So, now I am able to edit utf-8 and cp1250 files, but the second
              problem
              still persists: I still have corrupted messages and statusline.
              I get "<fd>" instead of "é" and such strange things in the messages.
              I also get something like "é" instead of "č" in statusline,
              as I mentioned above.

              Any ideas, why the messages and statusline are still displayed
              incorrectly?


              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            Your message has been successfully submitted and would be delivered to recipients shortly.