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

Re: .swp file left behind on Windows

Expand Messages
  • rpr
    ... So, what is the right way to write text files with utf-8 encoding so that they may be automatically editable on a multi-byte enabled system which do not
    Message 1 of 10 , Dec 9, 2008
    • 0 Attachment
      On Dec 8, 7:41 pm, Bram Moolenaar <B...@...> wrote:
      >
      > > Here is a file created on a Ubuntu 8.04 system that uses the UTF-8
      > > encoding, which is not default on MS Windows, and hence I put the
      > > encoding=utf-8 command in the modeline so that I can edit it also on
      > > Windows:
      >
      > That's the wrong way of doing things.  Never change 'encoding' from a
      > modeline!  Perhaps this should be disabled.  I can't think of any
      > possible way it would be useful.

      So, what is the right way to write text files with utf-8 encoding so
      that they may be automatically editable on a "multi-byte" enabled
      system which do not use the utf-8 encoding by default?

      In the header of HTML files the following tag may be used:
      <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">

      This instructs a web browser or a HTML editor about the encoding of
      the text in the HTML file so that it may be displayed and edited
      regardless of the local system encoding default.

      I'd like to achieve the same in vim for any text file: to put a
      command in the modeline so that vim, while opening the file, is able
      to recognize the character encoding used in the file and also to edit
      such text and save it in the same encoding. Is this possible in vim?

      -- rpr.
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_multibyte" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... [...] ... [...] There isn t. If you know that you will (even only occasionally) be editing files which can contain any Unicode codepoints, you should start
      Message 2 of 10 , Dec 9, 2008
      • 0 Attachment
        On 09/12/08 10:54, rpr wrote:
        > On Dec 8, 7:41 pm, Bram Moolenaar<B...@...> wrote:
        [...]
        >> That's the wrong way of doing things. Never change 'encoding' from a
        >> modeline! Perhaps this should be disabled. I can't think of any
        >> possible way it would be useful.
        >
        > So, what is the right way to write text files with utf-8 encoding so
        > that they may be automatically editable on a "multi-byte" enabled
        > system which do not use the utf-8 encoding by default?
        [...]

        There isn't. If you know that you will (even only occasionally) be
        editing files which can contain any Unicode codepoints, you should start
        Vim in UTF-8 even if that isn't your OS-default locale. With a Vim
        running with 'encoding' set to UTF-8 you can edit files in any
        encodings. Some of them will be recognized automatically by virtue of
        your 'fileencodings' (plural) option; for others you may have to use the
        ++enc argument of the ":edit" (or ":new", ":view", :sview", etc.)
        command, see ":help ++opt".

        Best regards,
        Tony.
        --
        Tertullian was born in Carthage somewhere about 160 A.D. He was a
        pagan, and he abandoned himself to the lascivious life of his city
        until about his 35th year, when he became a Christian .... To him is
        ascribed the sublime confession: Credo quia absurdum est (I believe
        because it is absurd). This does not altogether accord with historical
        fact, for he merely said:

        "And the Son of God died, which is immediately credible because
        it is absurd. And buried he rose again, which is certain
        because it is impossible."

        Thanks to the acuteness of his mind, he saw through the poverty of
        philosophical and Gnostic knowledge, and contemptuously rejected it.
        -- C. G. Jung, in Psychological Types

        (Tertullian was one of the founders of the Catholic Church).

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_multibyte" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Patrick Texier
        Le Tue, 9 Dec 2008 01:54:28 -0800 (PST), rpr a écrit dans le message ... File encoding is set with fileencoding option, not encoding . You can add a fenc
        Message 3 of 10 , Dec 9, 2008
        • 0 Attachment
          Le Tue, 9 Dec 2008 01:54:28 -0800 (PST), rpr a écrit dans le message
          <aedde531-f6af-4b0d-a156-8d214f0704df@...> :

          > I'd like to achieve the same in vim for any text file: to put a
          > command in the modeline so that vim, while opening the file, is able
          > to recognize the character encoding used in the file and also to edit
          > such text and save it in the same encoding. Is this possible in vim?

          File encoding is set with 'fileencoding' option, not 'encoding'. You can
          add a 'fenc' in a modeline but it's usefull only in rare cases (Latin9
          vs Latin1). With set fileencodings = ucs-bom,utf-8,latin1 (default value
          with Unicode) Vim will detect file encoding.

          You can read User Manual :help 45.3 for a good introduction.
          --
          Patrick Texier

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_multibyte" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Tony Mechelynck
          ... ...and if it detects the wrong value (let s say Vim detects latin1 on an iso-8859-2 file) you can reload the file with an override, as in ... See also
          Message 4 of 10 , Dec 9, 2008
          • 0 Attachment
            On 09/12/08 18:39, Patrick Texier wrote:
            > Le Tue, 9 Dec 2008 01:54:28 -0800 (PST), rpr a écrit dans le message
            > <aedde531-f6af-4b0d-a156-8d214f0704df@...> :
            >
            >> I'd like to achieve the same in vim for any text file: to put a
            >> command in the modeline so that vim, while opening the file, is able
            >> to recognize the character encoding used in the file and also to edit
            >> such text and save it in the same encoding. Is this possible in vim?
            >
            > File encoding is set with 'fileencoding' option, not 'encoding'. You can
            > add a 'fenc' in a modeline but it's usefull only in rare cases (Latin9
            > vs Latin1). With set fileencodings = ucs-bom,utf-8,latin1 (default value
            > with Unicode) Vim will detect file encoding.

            ...and if it detects the wrong value (let's say Vim detects latin1 on an
            iso-8859-2 file) you can reload the file with an override, as in

            :e ++enc=iso-8859-2

            See also ":help ++opt".

            >
            > You can read User Manual :help 45.3 for a good introduction.

            also the Vim Tip about Unicode, mentioned earlier in this thread.


            Best regards,
            Tony.
            --
            LAUNCELOT: At last! A call! A cry of distress ...
            (he draws his sword, and turns to CONCORDE)
            Concorde! Brave, Concorde ... you shall not have died in vain!
            CONCORDE: I'm not quite dead, sir ...
            "Monty Python and the Holy Grail" PYTHON (MONTY)
            PICTURES LTD

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_multibyte" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Mansing
            I tried changing enc= to fenc= in my mode line: but my Chinese text doesn t show up correctly (as if
            Message 5 of 10 , Dec 9, 2008
            • 0 Attachment
              I tried changing "enc=" to "fenc=" in my mode line:

              <!-- vim: set fo+=mM gfn=MingLiU\:h12 fenc=utf-8: -->

              but my Chinese text doesn't show up correctly (as if this option were
              omitted). I tried (after reading help 45.3 on ":edit ++enc=...") also
              "++enc=" and "\+\+enc=", but Vim says this is not a known option (for
              the mode line). Seems "enc=" is the only way that I can use to
              (automatically) tell Vim about my file encoding.

              Note that I am not complaining any problem: I am happy with "enc=" in my
              mode line as it works well with all context encodings I happened to use
              --Big5, GB2312, utf-8 etc. I am just perplexed to hear that this is the
              wrong way?

              mt 081210


              Patrick Texier wrote:
              > Le Tue, 9 Dec 2008 01:54:28 -0800 (PST), rpr a écrit dans le message
              > <aedde531-f6af-4b0d-a156-8d214f0704df@...> :
              >
              >> I'd like to achieve the same in vim for any text file: to put a
              >> command in the modeline so that vim, while opening the file, is able
              >> to recognize the character encoding used in the file and also to edit
              >> such text and save it in the same encoding. Is this possible in vim?
              >>
              > File encoding is set with 'fileencoding' option, not 'encoding'. You can
              > add a 'fenc' in a modeline but it's usefull only in rare cases (Latin9
              > vs Latin1). With set fileencodings = ucs-bom,utf-8,latin1 (default value
              > with Unicode) Vim will detect file encoding.
              >
              > You can read User Manual :help 45.3 for a good introduction.
              >

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_multibyte" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Tony Mechelynck
              ... not on the modeline but as an ex-command. You need a Vim version with +multi_byte compiled-in and your encoding MUST already be set (preferably somewhere
              Message 6 of 10 , Dec 9, 2008
              • 0 Attachment
                On 10/12/08 01:46, Mansing wrote:
                > I tried changing "enc=" to "fenc=" in my mode line:
                >
                > <!-- vim: set fo+=mM gfn=MingLiU\:h12 fenc=utf-8: -->
                >
                > but my Chinese text doesn't show up correctly (as if this option were
                > omitted). I tried (after reading help 45.3 on ":edit ++enc=...") also
                > "++enc=" and "\+\+enc=", but Vim says this is not a known option (for
                > the mode line). Seems "enc=" is the only way that I can use to
                > (automatically) tell Vim about my file encoding.

                :edit ++enc=utf-8 filename.ext

                not on the modeline but as an ex-command. You need a Vim version with
                +multi_byte compiled-in and your 'encoding' MUST already be set
                (preferably somewhere near the top of your vimrc) to utf-8.

                If you have 'enc' set to utf-8 and 'fencs' starting with ucs-bom,utf-8
                (which is the default once you set 'enc' to utf-8), UTF-8 files ought to
                be correctly recognized without the need for anything special on either
                a modeline or the ":edit" ex-command.

                You can NEVER edit correctly a file which contains characters which your
                current 'encoding' setting cannot represent. For instance, with
                'encoding' set to Latin1 you cannot edit Chinese text because there are
                no Chginese glyphs in Latin1.

                >
                > Note that I am not complaining any problem: I am happy with "enc=" in my
                > mode line as it works well with all context encodings I happened to use
                > --Big5, GB2312, utf-8 etc. I am just perplexed to hear that this is the
                > wrong way?
                >
                > mt 081210

                'ecoding' affects the representation of data for ALL files in Vim
                memory. If 'encoding' was previously set to GBK, and you have a GBK file
                in another split-window, or even in a hidden buffer, opening a file
                whose modeline sets 'encoding' to UTF-8 will make Vim regard ALL text in
                ALL files as UTF-8 text, but the internal data in buffers already in
                memory will NOT be changed, so the other file will still contain GBK
                data, which Vim will now try to interpret as UTF-8 data, with
                catastrophic results (you'll get a lot of "invalid" UTF-8 characters,
                and probably none of the Chinese text in the GBK file will be recognizable).

                OTOH, if 'encoding' is set to UTF-8, typing ":e ++enc=gbk gbkfile.txt"
                will correctly edit the file gbkfile.txt if it uses GBK charset. Vim
                (with +multi_byte and +iconv compiled-in) will be happy to convert the
                file's data, GBK => UTF-8 when reading and UTF-8 => GBK when writing --
                provided, of course, that you don't insert any hanzi which has no GBK
                representation.

                The only time when it is "safe" to change 'encoding' is when there are
                no nonempty buffers loaded into Vim. Your vimrc (which is sourced before
                actually loading any buffers) is one such "safe place". I recommend
                (whenever you run a Vim version with +multi_byte compiled-in) to set
                'encoding' to UTF-8 in your vimrc (after saving the previous 'encoding'
                value in 'termencoding' if the latter was empty), and never to change
                'encoding' later on.


                Best regards,
                Tony.
                --
                The new Congressmen say they're going to turn the government around. I
                hope I don't get run over again.

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