I save files in neovim way too often, I started like we all do, using :w, then I implemented a form of "autosave" that saved the file when I exited insert mode by pressing kj. But then I found out about the okuuva/auto-save.nvim plugin, which is a fork of the unmaintained pocco81/auto-save.nvim plugin.
The plugin works great, it adds a debounce delay that adds a delay to save the file after it's changed. There are several trigger events that can be configured, undo and redo works fine, and it also works when combined with autoformatting
Here's the link for my plugin configuration and setup
[ Ссылка ]
Here's a link to my keymaps file
[ Ссылка ]
Alternate between the last 2 tmux sessions or neovim buffers
[ Ссылка ]
How to view and paste images in neovim
[ Ссылка ]
Here's the code for reference, but instead of getting it from here, get it from the github repo:
return {
{
"okuuva/auto-save.nvim",
cmd = "ASToggle", -- optional for lazy loading on command
event = { "InsertLeave", "TextChanged" }, -- optional for lazy loading on trigger events
opts = {
--
-- All of these are just the defaults
--
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
execution_message = {
enabled = true,
message = function() -- message to print on save
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
end,
dim = 0.18, -- dim the color of `message`
cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea
},
trigger_events = { -- See :h events
immediate_save = { "BufLeave", "FocusLost" }, -- vim events that trigger an immediate save
defer_save = { "InsertLeave", "TextChanged" }, -- vim events that trigger a deferred save (saves after `debounce_delay`)
cancel_defered_save = { "InsertEnter" }, -- vim events that cancel a pending deferred save
},
-- function that takes the buffer handle and determines whether to save the current buffer or not
-- return true: if buffer is ok to be saved
-- return false: if it's not ok to be saved
-- if set to `nil` then no specific condition is applied
condition = nil,
write_all_buffers = false, -- write all buffers when the current one meets `condition`
-- Do not execute autocmds when saving
-- This is what fixed the issues with undo/redo that I had
-- [ Ссылка ]
noautocmd = false,
lockmarks = false, -- lock marks when saving, see `:h lockmarks` for more details
-- delay after which a pending save is executed (default 1000)
debounce_delay = 1000,
-- log debug messages to 'auto-save.log' file in neovim cache directory, set to `true` to enable
debug = false,
},
},
}
0:00 - Autosave demo
1:22 - Reddit post to autosave discussion
2:13 - Unmaintained plugin repo
2:40 - Maintained plugin repo
3:08 - auto-save.nvim plugin configuration
4:14 - debounce delay demo
5:12 - Keymap I used before to autosave
5:31 - How I switch between tmux sessions and alternate buffers
6:13 - How I view and pages images in neovim
Save neovim files automatically with auto-save.nvim
Теги
vimneovimneovim pluginsauto-save.nvimokuuvapocco81autosavefile savingneovim configurationneovim setupplugin configurationnvimluaneovim luaneovim keymapsgithubdotfilesdebounce delaylazy loadingvim pluginstext editorprogrammingneovim tutorialneovim guidedeveloper toolsneovim autosaveneovim autocmdpocco81/auto-save.nvimokuuva/auto-save.nvimneovim save automaticallyneovim autoformatneovim autocompleteneovim autosave autoformat