If I open files I created in Windows, the lines all end with ^M
.
How do I delete these characters all at once?
dos2unix is a commandline utility that will do this, or :%s/^M//g
will if you use Ctrl-v Ctrl-m to input the ^M, or you can :set ff=unix
and Vim will do it for you.
There is documentation on the fileformat setting, and the Vim wiki has a comprehensive page on line ending conversions.
Alternately, if you move files back and forth a lot, you might not want to convert them, but rather to do :set ff=dos
, so Vim will know it's a DOS file and use DOS conventions for line endings.
:%s/^M//g
should be:%s/\r//g
, because^M
just means "match capital "M" at the beginning of the line".Not if you do as the answer says and 'use ctrl-v ctrl-m to input the ^M'.
crtl-v is no good, on windows it pastes clipboard contents to the command line. Solution
:%s/\r//g
worked for me, cheers @Bunyk@ropata What you want on Windows is ctrl-q.
I must be missing something, because
set ff=unix
does nothing. Maybe it converts the file, but all of the^M
characters are still there.