vim Converting text files from DOS to UNIX with vi Converting a DOS Text file to a UNIX Text file


Quite often you have a file which was edited within DOS or Windows and you are viewing it under UNIX. This can look like the following when you view the file with vi.

First line of file^M
Next Line^M
And another^M

If you wish to remove the ^M, it can be that you delete each ^M by hand. Alternatively, in vi after hitting Esc you can enter the following at the command mode prompt:


Where ^M is entered with Ctrl and v together and then Ctrl and m together.

This executes the command from the first line '1' to the last line '$', the command is to substitute 's' the '^M' for nothing '' and to this globally 'g'.