writefile() 時の改行コード

試しに fileformat を指定してから結果を確認してみた.

set fileformat=dos
call writefile(a, "/tmp/dos")
set fileformat=mac
call writefile(a, "/tmp/mac")
set fileformat=unix
call writefile(a, "/tmp/unix")

set fileformat=dos
call writefile(a, "/tmp/dos2", "b")
set fileformat=mac
call writefile(a, "/tmp/mac2", "b")
set fileformat=unix
call writefile(a, "/tmp/unix2", "b")

これだとバイナリ版とそうでない版での違いはでる(最後の改行コード有無)が, 改行コードは同じもの.
windows でもいつも LF であるなら問題ないのだけど, windows vim 環境はないのであった.

writefile() 時に改行コードを設定するオプションはなさげ. いったいどうするんだろう.

 /* Always open the file in binary mode, library functions have a mind of
  * their own about CR-LF conversion. */

 ...
if (!binary || li->li_next != NULL)
    if (putc('\n', fd) == EOF)
    {
        ret = -1;
        break;
    }
https://code.google.com/p/vim/source/browse/src/eval.c

ふむむ..

2013/05/27 追記

:h writefile()
 ...
                Inserting CR characters needs to be done before passing {list}
                to writefile().