Create autorun script for neovim

This commit is contained in:
2025-12-05 07:58:53 +01:00
parent d20e87c963
commit 6b90ca82e3

22
2025/autorun.lua Normal file
View File

@@ -0,0 +1,22 @@
-- Use this to get the buffer ID where you want the output
-- echo nvim_get_current_buf()
vim.api.nvim_create_autocmd("BufWritePost", {
group = vim.api.nvim_create_augroup("AutoRunCode", { clear = true }),
pattern = "*.lua",
callback = function()
local bufnr = 21
vim.fn.jobstart({ "lua", "Day5/Day5.lua" }, {
stdout_buffered = true,
on_stdout = function(_, data)
if data then
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, data)
end
end,
on_stderr = function(_, data)
if data then
vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, data)
end
end,
})
end,
})