Reputation: 31
i use vim-auto-save for vim and autosave.nvim for neovim, i set both to save only in InsertLeave
but in insert mode, when i press Enter within a pair of braces {}, (), []
, to insert a newline, the plugin saves the file automatically, and i prevent this using: autocmd TextChanged,TextChangedI <buffer> silent noautocmd
in my .vimrc and tried to apply the same to init.lua using vim.cmd: vim.cmd("autocmd TextChanged,TextChangedI <buffer> silent noautocmd")
but this doesn't work
Upvotes: 1
Views: 218
Reputation: 237
I use this plugin for autosaving in nvim. This works well. You can add these lines in your plugin config file for auto saving in normal mode and after text change event.
{
enabled = true,
execution_message = {
message = function()
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
end,
dim = 0.18,
},
trigger_events = {"InsertLeave", "TextChanged"},
condition = function(buf)
local fn = vim.fn
local utils = require("auto-save.utils.data")
if
fn.getbufvar(buf, "&modifiable") == 1 and
utils.not_in(fn.getbufvar(buf, "&filetype"), {}) then
return true
end
return false
end,
write_all_buffers = false,
debounce_delay = 135,
callbacks = {
enabling = nil,
disabling = nil,
before_asserting_save = nil,
before_saving = nil,
after_saving = nil,
}
}
This is the default configuration of this plugin, consider configuring yourself as you want
Upvotes: 0