I want a function to append text to a file (not a buffer) in vim. As far as I can see, there is no appendfile(). But the desired functionality can be emulated with readfile() and writefile():
fu! TQ84_log (S)
let l:f = readfile('my.log')
call add(l:f, a:S)
call writefile(l:f, 'my.log')
endfu
Since my.log can grow quite large, I'd rather not read and write the entire file when I want to add a line. So, I came up with another "solution":
fu! TQ84_log (S)
silent execute "!echo " . a:S . ">> my.log"
endfu
This works (on windows, that is) as expected. Yet, when I invoke TQ84_log(), that cmd.exe window pops up for a short time. This is a bit distracting.
Is there a better solution for my problem?
functioninstead offuand use more readable variable names. If you don't do that for others at least do that for yourself.