Tuesday, February 8, 2011

replace ^M with newline in vim

Sometimes, well, rarely, I need to edit a windows file in linux. And when this happens I usually need to replace the DOS newline with a unix newline.

vi(m) to the rescue:

:%s/^M/\r/g


To get a ^M, you need to do Ctrl-V followed by Ctrl-M

2 comments:

  1. Thanks for supplying the "To get a ^M, you need to do Ctrl-V followed by Ctrl-M" part of instruction! I've found 10 other tutorials/tips on this that neglect this critical step.

    Rouble to the rescue!

    ReplyDelete