DOS to Linux line endings in VIM

Switching between Windows and Linux machines every day, you’ll undoubtedly end up with files in the Linux system with DOS line endings. You can easily change the line endings in the editor VIM using the following commands:

:w ++ff=dos
:w ++ff=mac
:w ++ff=unix

You can also change the file from the command line directly without “opening” VI, e.g.

vi +':wq ++ff=unix' ./some_file.txt

There is also a small common utility to help with line endings called dos2unix. It allows you to easily convert files from the command line.

Hope this helps!

This entry was posted in Bash, Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *