Managing and Munging Line Endings in Vim

If you have opened a file, and see a bunch “^M” or “^J” characters in it, chances are that for some reason Vim is confused as to the line-ending type.
You can force it to interpret the file with a specific line-ending by using the “++ff” argument and asking Vim to re-read the file using the “:e” command:

:e ++ff=unix
:e ++ff=mac
:e ++ff=dos

This will not actually change any characters in the file, just the way the file is interpreted.
If you want to resave the file with the new line-ending format, you can give the “++ff” argument to the “:w” command:

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

Alternatively, you can just set the line-ending format, and the file will be written out with the new line ending format the next time it is saved:

:set ff=unix
:set ff=mac
:set ff=dos

Leave a Reply

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