Try using readfile() + writefile() .
If you are using Vim 7.3.150+, ( or if you are absolutely sure that this file ends with \n ):
function AppendToFile(file, lines) call writefile(readfile(a:file)+a:lines, a:file) endfunction
For Vim older than 7.3.150:
" lines must be a list without trailing newlines. function AppendToFile(file, lines) call writefile(readfile(a:file, 'b')+a:lines, a:file, 'b') endfunction " Version working with file *possibly* containing trailing newline function AppendToFile(file, lines) let fcontents=readfile(a:file, 'b') if !empty(fcontents) && empty(fcontents[-1]) call remove(fcontents, -1) endif call writefile(fcontents+a:lines, a:file, 'b') endfunction
source share