Monday, May 6, 2019

Create buffer without opening a window

I would like to create a new buffer "in the background", without opening
any new window, put some text into the buffer then write it to disk,
without ever showing the buffer (the reason why I am not populating
a List and use writefile() directly is that I need to perform some text
manipulation such as reindenting the text). I thought that something
like this would do it:

let n = bufnr('my new buffer', 1)
call setbufline(n, 1, 'hello')
call writefile(getbufline(n, 1, "$"), './foo.txt')

but the buffer stays empty and setbufline() returns 1. What should I do
instead?

Thanks,
Life.


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: