Search code examples
vimnewlinecarriage-returnlinefeed

^M at the end of every line in Vim


When I am editing source files using Vim and other editors, sometimes I get these ^M characters at the end of each line. I think that it has something to do with editing a file on Windows and then on Linux. How can I remove all of these automatically?


Solution

  • As a command, type

    :%s/^M$//
    

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