diff --git a/lua/config/autocommands.lua b/lua/config/autocommands.lua index 8dccfcf..14fec4c 100644 --- a/lua/config/autocommands.lua +++ b/lua/config/autocommands.lua @@ -113,10 +113,15 @@ vim.api.nvim_create_autocmd('TextYankPost', { }) -- Autosave -vim.api.nvim_create_user_command('AutosaveToggle', function() - vim.g.autosave_enabled = not vim.g.autosave_enabled - print('Autosave: ' .. (vim.g.autosave_enabled and 'ON' or 'OFF')) -end, {}) +vim.api.nvim_create_user_command('ToggleAutoWrite', function() + local value = not vim.o.autowrite + vim.o.autowrite = value + vim.o.autowriteall = value + + vim.notify('autowrite: ' .. (value and 'enabled' or 'disabled'), vim.log.levels.INFO) +end, { + desc = 'Toogle Autowrite', +}) vim.api.nvim_create_autocmd('FocusGained', { group = aug, diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 6e33eae..1651cfe 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -95,9 +95,8 @@ u.map('n', ']e', diagnostic_goto(true, 'ERROR'), { desc = 'Next Error' }) u.map('n', '[e', diagnostic_goto(false, 'ERROR'), { desc = 'Prev Error' }) -- autosave -u.map('n', 'as', function() - local invert = not vim.opt.autowrite - vim.opt.autowrite = invert +vim.keymap.set('n', 'as', function() + u.toggle_autowrite() end, { desc = 'Toggle Autowrite' }) -- undotree diff --git a/lua/config/options.lua b/lua/config/options.lua index 1d19d0c..7f60c74 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -38,7 +38,8 @@ vim.opt.wildignore:append( ) vim.opt.completeopt = { 'menuone', 'noinsert', 'preview' } vim.opt.completetimeout = 100 -- Limit sources delay -vim.opt.autowrite = true +vim.o.autowrite = true +vim.o.autowriteall = true vim.opt.confirm = true vim.opt.winwidth = 10 vim.opt.winborder = 'rounded' @@ -68,7 +69,6 @@ vim.opt.foldenable = true vim.opt.foldlevel = 10 vim.opt.foldnestmax = 10 vim.opt.scrolloffpad = 1 -vim.opt.autowrite = true -- also, see: AutosaveToggle vim.g.maplocalleader = ',' vim.g.blink_enabled = true