What is DOS in Vim?

What is DOS in Vim?

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.

Why is Vim adding M?

The real question is why does Vim sometimes automatically detect the line endings and display correctly, and sometimes not. You will see the ^M character if the file has mismatched line endings. Use the command provided by Tomasz, then type :fileformat={unix|dos|mac} depending on which OS you’re targeting.

How do I change the file format in Vim?

Open your file in Vim and, in normal mode, type :set ff? to see what the file format is. If it is DOS, then type :set ff=unix to change it to Unix.

What is so special about vim?

Vim allows you to be efficient by forcing you to only use the keyboard (yes, that means no more mouse!) and then giving you the ability to use existing keyboard shortcuts as well as customize and create new ones for completing repetitive tasks quickly.

Why does Vim feed the correct set of lines?

That’s the whole point, Vim has parsed the file from its file format, so now it’s no longer a “DOS newline” but simply a “newline”, so Vim will just show it as such. Vim still knows this file was a DOS fileformat file, so when it writes it back to disk, it will preserve that format and use “DOS newlines”.

How to save a DOS file in Vim?

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. This can also be used as saving operation (:w alone will not save using the line endings you see on screen):

How to delete DOS line endings in Vim?

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.

To fix this, you need to tell Vim to read the file again using dos file format. When reading as dos, all CRLF line endings, and all LF-only line endings, are removed. Then you need to change the file format for the buffer and save the file.