remove ^M in vi

If you need to remove ^M (windows ending line character) in vi you have to open specific document in vi and type :

:%s/^M//g

(To get the ^M hold the control key, press V then M (Both while holding the control key) and the ^M will appear.)

This command will find all occurances and replace them with nothing. Here,the :%s is a basic search and replace command in vi. It tells vi to replace the regular expression between the first and second slashes (^M) with the text between the second and third slashes (nothing in this case). The g at the end directs vi to search and replace globally (all occurrences).

Advertisements

2 Comments on “remove ^M in vi”

  1. AnnasMom07 says:

    I really appreciate your posting this. This was the first tip I found for this issue that actually worked for me.

  2. sandrar says:

    Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s