Тёмный

Save neovim files automatically with auto-save.nvim 

linkarzu
Подписаться 464
Просмотров 587
50% 1

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
github.com/linkarzu/dotfiles-...
Here's a link to my keymaps file
github.com/linkarzu/dotfiles-...
Alternate between the last 2 tmux sessions or neovim buffers
• Alternate between the ...
How to view and paste images in neovim
• View and paste images ...
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
-- github.com/okuuva/auto-save.n...
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

Наука

Опубликовано:

 

28 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 4   
@reaperal7479
@reaperal7479 5 дней назад
Do I need to Esc? Or on change after the every delay interval it get saved
@linkarzu
@linkarzu 2 дня назад
That is correct, when you leave insert mode, it will autosave, or if you leave the buffer or focus is lost (switch to another app) even if you're in insert mode it will autosave due to the "immediate_save" config. I'm rarely in insert mode anyway, as soon as I'm done typing, I go out of insert mode, and the way I do it is not with but I prefer instead. Just personal preference.
@ingenarelitems
@ingenarelitems 13 дней назад
it's kinda crazy cz i have the same desktop background lol.
@linkarzu
@linkarzu 13 дней назад
I tried looking for a different a few days ago, but I just couldn't find something better 😂
Далее
Linux Mint Tips & Tricks
17:59
Просмотров 176 тыс.
Recycled Car Tyres Get a Second Life! ♻️
00:58
Просмотров 2,8 млн
Gale Now VS Then Edit🥵 #brawlstars #shorts
00:15
Просмотров 317 тыс.
What is the Smallest Possible .EXE?
17:57
Просмотров 78 тыс.
I Love Neovim But I WONT Use It | Prime Reacts
23:22
Просмотров 109 тыс.
I Rewrote My Entire Neovim Config...
11:09
Просмотров 36 тыс.
⚡flash.nvim - Weekly Neovim Plugin
11:14
Просмотров 11 тыс.
Switching to LAZYVIM
12:42
Просмотров 33 тыс.
Why Neovim nerds are so obsessed with the terminal
6:44
Why oil.nvim is the best directory plugin
9:12
Просмотров 22 тыс.
Неразрушаемый смартфон
1:00
Просмотров 1,8 млн
Самый СТРАННЫЙ смартфон!
0:57
Просмотров 31 тыс.
Телефон в воде 🤯
0:28
Просмотров 1,2 млн