Skip to content

Commit 994d4d0

Browse files
committed
feat: auto-save file
1 parent c56cc54 commit 994d4d0

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

lua/custom-autocmd.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,17 @@ api.nvim_create_autocmd("BufWritePost", {
292292
end
293293
end,
294294
})
295+
296+
api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, {
297+
group = api.nvim_create_augroup("auto_save", { clear = true }),
298+
pattern = { "*" },
299+
desc = "Auto save current file",
300+
callback = function(ev)
301+
local is_readonly = vim.api.nvim_get_option_value("readonly", { buf = ev.buf })
302+
local is_modifiable = vim.api.nvim_get_option_value("modifiable", { buf = ev.buf })
303+
304+
if not is_readonly and is_modifiable then
305+
vim.cmd([[silent! update]])
306+
end
307+
end,
308+
})

0 commit comments

Comments
 (0)