How to find/remove "^M" in VI editor

Moderator: cah

Post Reply
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

How to find/remove "^M" in VI editor

Post by cah »

^ is "CTRL" key.
When one simply press "CRTL+M" together in VI, VI treats it as the "Enter" key. Therefore, one needs to "escape" the control key by using "CTRL+V" in front of the control characters.

Find "^M":

Code: Select all

/^M
You will see "^" when you press "CTRL+V" together. Then, "CTRL+M" will have "M" show up after "^". Then, press "Enter" key to find the "^M" character in the document.

Replace/remove "^M":

Code: Select all

:1,$s/^M//g
1. Type ":1,$s/" first.
2. Type "CTRL+V" and "CTRL+M".
3.Type "/g" and "Enter" key to execute.
CAH, The Great
Post Reply