I want to write the contents of a buffer with
writefile(). However I do not want to use binary mode because I suspect it has (undocumented) side effects.
My question concerns noeol files, i.e. files whose last line isn't terminated by an EOL.
If I set the
nofixeol option, open a noeol file, and write it with
:w, Vim writes the file as-is, i.e. without adding an EOL to the last line. This is what I expect.
However if I use
writefile() instead of
:w, Vim does add an EOL to the last line despite
nofixeol. This isn't what I expect or want.
$ echo -n abc > foo $ vim --cmd 'set nofixeol' foo :wq bar $ od -c bar 0000000 a b c
$ echo -n abc > foo $ vim --cmd 'set nofixeol' foo :call writefile(getline(1,'$'), 'bar') :q $ od -c bar 0000000 a b c \n
Is there a way to use
writefile() on noeol files so it doesn't add an EOL to the last line (avoiding binary mode)?
Alternatively, what side effects does binary mode have? For one thing it adjusts
expandtab, according to
:h edit-binary. What else might it do?