Text file with ^M on each line

后端 未结 3 1281
萌比男神i
萌比男神i 2020-12-28 22:11

I just got a source code file from a friend. The file was created in UNIX. When I opened it in Windows using NotePad++, each line had one extra blank line.

Puzzled,

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 22:23

    Those are DOS/Windows-style line-endings (to be pedantic that's what they're commonly known as now but most early non-UNIX OSes like CP/M and OS/2 had them as well). On the various Unices, line-endings are \n. In DOS/Windows the line-endings are \r\n (CR+LF or Carriage-Return and Line-Feed). The \r is what shows up as ^M. To remove them in vim, I do:

    :%s/^M//
    

    You can get the ^M by doing CTRL+V and then CTRL+M

    If you are on a UNIX system, you can use dos2unix.

提交回复
热议问题