docs:vim:fileformats

fileformats

If your file has consistent line endings throughout, but you have had a 'ff' detection problem, the best fix is to force Vim to use the correct format with the :e command:

:e ++ff=mac

If your file does not have consistent line endings throughout, you need to force vim to load it a certain way without any assumptions. This example is where the output from a grep command was run and captured to a file. Some of the results were from dos files, and others from unix files, so the line endings aren't consistent, and vim shows us ^M characters because it is interpreted as unix.

:set ffs=dos
:e ++ff=dos

In this case you should see vim list [CR missing] in the status line after loading the file. Vim has fixed the line endings for you, so now you can simply do this to save the file and open it as a corrected dos file:

:w
:e!

This will read a file (assuming “dos”), convert line-endings to unix (<CR><NL> pairs will be <NL>):

:e file
:set fileformat=unix
:w
  • docs/vim/fileformats.txt
  • Last modified: 2009/06/24 17:39
  • by billh