Created
November 19, 2023 20:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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