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

Re: until when the ^M pestiferous problem?

Expand Messages
  • Hans Fugal
    I think I was able to wade through your message and if I am understanding correctly you want a ^M to not be displayed just before the newline. What would you
    Message 1 of 6 , Nov 30, 2001
    • 0 Attachment
      I think I was able to wade through your message and if I am
      understanding correctly you want a ^M to not be displayed just before
      the newline. What would you like if there are two ^M's just before the EOL?
      For that is exactly what you have in these files. Go ahead and load up
      ibm1.txt and follow my lead.

      :set ff?
      -> fileformat=dos
      :e! ++ff=unix

      see the ^M^M at the end of each line? Vim is correctly interpreting
      <CR><NL> to mean newline and correctly identifying these files as dos
      files. The extra <CR> is being displayed because it is not before the
      <NL>. So in other words, vim already is doing exactly what you ask.

      So how do you fix this file that has apparently gotten hosed? Just do
      this command:

      :%s/^M//g

      then make sure it is in dos mode

      :set ff=dos

      then save it. Note that the ^M in the :%s command is created by typing
      <CTRL-V><CTRL-M> (or even <CTRL-V><ENTER>)

      As a side note, vim 5.7.2 didn't have the capability to do ++ff= and
      apparently didn't work the way the manuals said in escaping backslashes
      (iow, ":e! +set\ ff=unix" did not work). If you're using an older vim
      that can't do ++ff= then do this:

      :e ibm1.txt
      :set ff=unix
      :w
      :e

      And you will see that it is open in dos mode without the extra ^M's.
      The reverse is perhaps how it ended up this way in the first place.
      Sometimes files get corrupted and have mixed newline types, and vim has
      to make its best guess (and probably guessed unix). Then you probably
      did :set ff=dos and saved it. The next time you opened it it had extra
      ^M's (because if it's in ff=dos and you save it, each newline is saved
      as <CR><NL>)

      In short, vim is behaving exactly correct. Without vim's help you would
      never have realized that your files were messed up. Thank goodness for
      vim!

      HTH
      Hans :)

      --
      You can't appreciate Shakespeare until you've read him in the original Klingon.
    Your message has been successfully submitted and would be delivered to recipients shortly.