Thursday, July 21, 2005

HOWTO replace ^M with real carriage return using vi

You can search for or replace a carriage return by using the character that is created when you hit these buttons:

<CTRL><RETURN>

Occassionally, you'll see a document in vi that has lots of ^M characters. To replace them with nothing type this:

:%s/<CTRL><M>//g

Remember that <CTRL><M> means you actually hit those buttons on your keyboard, not type 'less-than' symbols, etc. This is a search and replace tool in vi, the '%' makes it search across all lines, the 'g' on the end makes it replace every instance on that line.

If you want to replace those guys with a real carriage return type this:

:%s/<CTRL><M>/<CTRL><RETURN>/g

0 Comments:

Post a Comment

<< Home