Friday, September 19, 2008

Remove ^M Characters in vi

Alright, I've previously blogged this before, but if you can tell from my previous post, I was blogless for a while so, now to fill this new blog with new and old posts.

Anyhow, I'm sure any of you Vi guys & gals out there have run into this wonderful issue of having "^M" appear at the end of each line. This is especially true if you work with *nix and Windows or if your co-workers use Windows.

So, to quickly get rid of this in vi enter the following:
:%s/ctrl+V ctrl+M//g

It will display as: ^M

*Note: Do NOT type in shift+6 shift+m. Remember these are special characters and they need to be entered as so.

That's it! And Bob's your uncle!

Alternatively, you can use sed to make the search/replace. Notice the vi code looks pretty much the same as the sed arguments.

Cheers!

No comments: