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

.swp file left behind on Windows

Expand Messages
  • rpr
    On vim/gvim 7.1 and 7.2 for MS Windows I noticed that there are problems with editing files when the file path contains non-ASCII characters and you change the
    Message 1 of 10 , Dec 8, 2008
    • 0 Attachment
      On vim/gvim 7.1 and 7.2 for MS Windows I noticed that there are
      problems with editing files when the file path contains non-ASCII
      characters and you change the encoding with ":set encoding" command.

      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:

      ------------------------------------------------------------
      This is a test file.
      Robert Premuž
      vim:columns=80:tw=80:encoding=utf-8
      ------------------------------------------------------------

      If the file path contains only ASCII characters, e.g. "c:\temp\test",
      on an NTFS partition of a MS Windows system everything works fine
      while editing the file.

      But if the file name (or path) is changed so that it contains
      non-ASCII characters, e.g. "c:\test\test-ž", after editing the file
      the .test-ž.swp file is left behind (even if the file was not modified
      at all).

      This problem disappears if the encoding=utf-8 is removed from the
      modeline but then non-ASCII characters are not displayed correctly as
      vim uses the default system encoding, which is not utf-8.

      On Windows I also noticed that if the file path contains non-ASCII
      characters and you change the file encoding with ":set encoding" vim
      also changes the encoding of the file path (displayed on the window
      title bar in gvim)! It seems that this is the cause of the .swp file
      left behind. On Ubuntu I don't notice such problem.

      This was tested on MS Windows XP Pro. SP3 and
      MS Windows Server 2003 SP2.

      Please confirm this problem. Is it a known issue?
      I also send this to bugs@....

      -- rpr. /Robert Premuž/

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_multibyte" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... Yes, and at http://vim.wikia.org/Working_with_Unicode you ll find a tip which I put together when I was still on Windows (Win98 I think), and the current
      Message 2 of 10 , Dec 8, 2008
      • 0 Attachment
        On 08/12/08 19:41, Bram Moolenaar wrote:
        >
        > Robert Premu wrote:
        >
        >> On vim/gvim 7.1 and 7.2 for MS Windows I noticed that there are
        >> problems with editing files when the file path contains non-ASCII
        >> characters and you change the encoding with ":set encoding" command.
        >
        > That is to be expected. When you change 'encoding' all text currently
        > in memory that contains non-ASCII characters may become invalid. That
        > includes file names.
        >
        >> 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.
        >
        >> ------------------------------------------------------------
        >> This is a test file.
        >> Robert Premuž
        >> vim:columns=80:tw=80:encoding=utf-8
        >> ------------------------------------------------------------
        >>
        >> If the file path contains only ASCII characters, e.g. "c:\temp\test",
        >> on an NTFS partition of a MS Windows system everything works fine
        >> while editing the file.
        >>
        >> But if the file name (or path) is changed so that it contains
        >> non-ASCII characters, e.g. "c:\test\test-ž", after editing the file
        >> the .test-ž.swp file is left behind (even if the file was not modified
        >> at all).
        >>
        >> This problem disappears if the encoding=utf-8 is removed from the
        >> modeline but then non-ASCII characters are not displayed correctly as
        >> vim uses the default system encoding, which is not utf-8.
        >>
        >> On Windows I also noticed that if the file path contains non-ASCII
        >> characters and you change the file encoding with ":set encoding" vim
        >> also changes the encoding of the file path (displayed on the window
        >> title bar in gvim)! It seems that this is the cause of the .swp file
        >> left behind. On Ubuntu I don't notice such problem.
        >>
        >> This was tested on MS Windows XP Pro. SP3 and
        >> MS Windows Server 2003 SP2.
        >>
        >> Please confirm this problem. Is it a known issue?
        >> I also send this to bugs@....
        >
        > The solution is to set 'encoding' before editing any file. Best is to
        > do this near the top of your vimrc file.
        >
        > It's very difficult to go through all stored text and convert everything
        > the moment you change 'encoding'. I have done it for the command line
        > arguments, since that is something you can't avoid. For some text it's
        > actually better not to do the conversion, because it was invalid before
        > switching 'encoding'.
        >

        Yes, and at http://vim.wikia.org/Working_with_Unicode you'll find a tip
        which I put together when I was still on Windows (Win98 I think), and
        the current version was maybe Vim 6.1 or thereabouts.

        It includes an explanation in plain English of what the various
        '*encoding*' options are for, and a code snippet which can be copied to
        your vimrc in order to set your Vim to UTF-8 and have everything still
        work (including, if you have them, accented characters and dead keys on
        your "national" keyboard). I'm still using that same code with very few
        changes.


        Best regards,
        Tony.
        --
        Yes, but which self do you want to be?

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_multibyte" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Mansing
        Rats! I tag the following mode line to all of my Chinese text files, to mark their encoding and font set etc.:
        Message 3 of 10 , Dec 8, 2008
        • 0 Attachment
          Rats! I tag the following mode line to all of my Chinese text files, to
          mark their encoding and font set etc.:

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

          I do that to avoid the ugly Latin in CJK font sets (for normal English
          text files) and to avoid the use of a BOM. I am running Windows (Vista).

          mt 081209


          Bram Moolenaar 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.
          >
          > . . .

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_multibyte" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • 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 4 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 5 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 6 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 7 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 8 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 9 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.