option sets the <EOL> style for a file:
'fileformat' characters name ~
"dos" <CR><NL> or <NL> DOS format *DOS-format*
"unix" <NL> Unix format *Unix-format*
"mac" <CR> Mac format *Mac-format*
When reading a file, the mentioned characters are interpreted as the <EOL>.
In DOS format (default for Windows), <CR><NL> and <NL> are both interpreted as
the <EOL>. Note that when writing the file in DOS format, <CR> characters will
be added for each single <NL>. Also see |file-read|.
When writing a file, the mentioned characters are used for <EOL>. For DOS
format <CR><NL> is used. Also see |DOS-format-write|.
You can read a file in DOS format and write it in Unix format. This will
replace all <CR><NL> pairs by <NL> (assuming 'fileformats' includes "dos"): >
:e file
:set fileformat=unix
:w
If you read a file in Unix format and write with DOS format, all <NL>
characters will be replaced with <CR><NL> (assuming 'fileformats' includes
"unix"): >
:e file
:set fileformat=dos
:w
If you start editing a new file and the 'fileformats' option is not empty
(which is the default), Vim will try to detect whether the lines in the file
are separated by the specified formats. When set to "unix,dos", Vim will
check for lines with a single <NL> (as used on Unix) or by a <CR><NL> pair
(MS-Windows). Only when ALL lines end in <CR><NL>, 'fileformat' is
set to "dos", otherwise it is set to "unix". When 'fileformats' includes
"mac", and no <NL> characters are found in the file, 'fileformat' is set to
"mac".
If the 'fileformat' option is set to "dos" on non-MS-Windows systems the
message "[dos]" is shown to remind you that something unusual is happening. On
MS-Windows systems you get the message "[unix]" if 'fileformat' is set to
"unix". On all systems you get the message "[mac]" if 'fileformat' is set to
"mac".
If the 'fileformats' option is empty and DOS format is used, but while reading
a file some lines did not end in <CR><NL>, "[CR missing]" will be included in
the file message.
If the 'fileformats' option is empty and Mac format is used, but while reading
a file a <NL> was found, "[NL missing]" will be included in the file message.
If the new file does not exist, the 'fileformat' of the current buffer is used
when 'fileformats' is empty. Otherwise the first format from 'fileformats' is
used for the new file.
Before editing binary, executable or Vim script files you should set the
'binary' option. A simple way to do this is by starting Vim with the "-b"
option. This will avoid the use of 'fileformat'. Without this you risk that
single <NL> characters are unexpectedly replaced with <CR><NL>.
END OF LINE AND END OF FILE *eol-and-eof*
Vim has several options to control the file format:
'fileformat' the <EOL> style: Unix, DOS, Mac
'endofline' whether the last line ends with a <EOL>
'endoffile' whether the file ends with a CTRL-Z
'fixendofline' whether to fix eol and eof
The first three values are normally detected automatically when reading the
file and are used when writing the text to a file. While editing the buffer
it looks like every line has a line ending and the CTRL-Z isn't there (an
exception is when 'binary' is set, it works differently then).
The 'fixendofline' option can be used to choose what to write. You can also
change the option values to write the file differently than how it was read.
Here are some examples how to use them.
If you want files in Unix format (every line NL terminated): >
setl ff=unix fixeol
You should probably do this on any Unix-like system. Also modern MS-Windows
systems tend to work well with this. It is recommended to always use this
format for Vim scripts.
If you want to use an old MS-DOS file in a modern environment, fixing line
endings and dropping CTRL-Z, but keeping the <CR><NL> style <EOL>: >
setl ff=dos fixeol
This is useful for many MS-Windows programs, they regularly expect the
<CR><NL> line endings.
If you want to drop the final <EOL> and