Skip to content

Instantly share code, notes, and snippets.

@Mr-Jack82
Created November 19, 2023 20:04
Show Gist options
  • Select an option

  • Save Mr-Jack82/8addb04a846f20212a559812253c1318 to your computer and use it in GitHub Desktop.

Select an option

Save Mr-Jack82/8addb04a846f20212a559812253c1318 to your computer and use it in GitHub Desktop.
Autocmd for auto save in Neovim like variant instead of use 907th/vim-auto-save
-- Taken from: https://github.com/LintaoAmons/CoolStuffes/blob/5b117d662f1f64e528545d584f5781f4522092c7/lazyvim/.config/nvim/lua/config/autocmds.lua#L5
-- HACK: Autosave
local function save()
local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_call(buf, function()
vim.cmd("silent! write")
end)
end
vim.api.nvim_create_augroup("AutoSave", {
clear = true,
})
vim.api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, {
callback = function()
save()
end,
pattern = "*",
group = "AutoSave",
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment