Write To A Neovim Buffer With A Lua Script
This is how I'm writing the output for my Neovim Auto-Typer
vim.api.nvim_paste("alfa bravo charlie", false, -1)
It Works With Sleep
The most important thing for me about this approach is that you can sleep between invocations and things will work as expected. For example, if you have Neovim 0.10 or better, you can do this:
vim.api.nvim_paste("alfa", false, -1)
vim.uv.sleep(1500)
vim.api.nvim_paste("bravo", false, -1)
That will output "alfa" at the current cursor position, wait 1.5 seconds, then output "bravo".
I spent a solid day trying to figure that out and never found nvim_paste()
in the docs. I never would have if it wasn't for someone in chat pointing it out to me. ("paste" is just too overloaded a term with folks looking for how to paste from the system)
There's also nvim_input()
but the suggestion is to use nvim_paste()
in most circumstances. See the docs for more details.
-- end of line --