Page 1 of 1

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

Posted: Tue Jan 10, 2017 3:08 pm
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.