^M at the end of every line in vim

前端 未结 9 1884
独厮守ぢ
独厮守ぢ 2020-11-29 17:37

When I am editing source files using vim and other editors sometimes at the end of the line I get these ^M characters at the end of each line. I think that it has something

9条回答
  •  有刺的猬
    2020-11-29 18:17

    This worked for me in a file that had everything on one line:

    First find all matches

    :%s/^M//
    

    (To get ^M, press ^V ^M, where ^ is Ctrl on most keyboards)

    Then replace with newlines

    :%s//\r/g
    

    Combined command would be:

    :%s/^M/\r/g
    

提交回复
热议问题