mirror of
https://github.com/zoriya/auto-save.nvim.git
synced 2026-08-09 15:46:58 +00:00
139 lines
4.1 KiB
Markdown
139 lines
4.1 KiB
Markdown
<p align="center">
|
|
<h2 align="center">🧶 auto-save.nvim</h2>
|
|
</p>
|
|
|
|
<p align="center">
|
|
Automatically save your changes in NeoVim
|
|
</p>
|
|
|
|
<p align="center">
|
|
<a href="https://github.com/Pocco81/auto-save.nvim/stargazers">
|
|
<img alt="Stars" src="https://img.shields.io/github/stars/Pocco81/auto-save.nvim?style=for-the-badge&logo=starship&color=C9CBFF&logoColor=D9E0EE&labelColor=302D41"></a>
|
|
<a href="https://github.com/Pocco81/auto-save.nvim/issues">
|
|
<img alt="Issues" src="https://img.shields.io/github/issues/Pocco81/auto-save.nvim?style=for-the-badge&logo=bilibili&color=F5E0DC&logoColor=D9E0EE&labelColor=302D41"></a>
|
|
<a href="https://github.com/Pocco81/auto-save.nvim">
|
|
<img alt="Repo Size" src="https://img.shields.io/github/repo-size/Pocco81/auto-save.nvim?color=%23DDB6F2&label=SIZE&logo=codesandbox&style=for-the-badge&logoColor=D9E0EE&labelColor=302D41"/></a>
|
|
</p>
|
|
|
|
|
|
|
|
### 📢 Disclaimer: Breaking Change
|
|
|
|
This plugin has been renamed from `AutoSave` to `auto-save`, and this repository has accordingly moved from `pocco81/AutoSave.nvim` to `pocco81/auto-save.nvim`. To prevent errors with your configuration, make sure to update both the name and the repository url in your config!
|
|
|
|
|
|
|
|
### 📋 Features
|
|
|
|
- automatically save your changes so the world doesn't collapse
|
|
- highly customizable:
|
|
- conditionals to assert whether to save or not
|
|
- execution message (it can be dimmed and personalized)
|
|
- events that trigger auto-save
|
|
- debounce the save with a delay
|
|
- multiple callbacks
|
|
- automatically clean the message area
|
|
|
|
|
|
|
|
### 📚 Requirements
|
|
|
|
- Neovim >= 0.5.0
|
|
|
|
|
|
|
|
### 📦 Installation
|
|
|
|
Install the plugin with your favourite package manager:
|
|
|
|
<details>
|
|
<summary><a href="https://github.com/wbthomason/packer.nvim">Packer.nvim</a></summary>
|
|
|
|
```lua
|
|
use({
|
|
"Pocco81/auto-save.nvim",
|
|
config = function()
|
|
require("auto-save").setup {
|
|
-- your config goes here
|
|
-- or just leave it empty :)
|
|
}
|
|
end,
|
|
})
|
|
```
|
|
|
|
</details>
|
|
|
|
<details>
|
|
<summary><a href="https://github.com/junegunn/vim-plug">vim-plug</a></summary>
|
|
|
|
```vim
|
|
Plug 'Pocco81/auto-save.nvim'
|
|
lua << EOF
|
|
require("auto-save").setup {
|
|
-- your config goes here
|
|
-- or just leave it empty :)
|
|
}
|
|
EOF
|
|
```
|
|
|
|
</details>
|
|
|
|
|
|
|
|
### ⚙️ Configuration
|
|
|
|
**auto-save** comes with the following defaults:
|
|
|
|
```lua
|
|
{
|
|
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it)
|
|
execution_message = {
|
|
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 = {"InsertLeave", "TextChanged"}, -- vim events that trigger auto-save. See :h events
|
|
-- function that 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
|
|
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 -- met condition(s), can save
|
|
end
|
|
return false -- can't save
|
|
end,
|
|
write_all_buffers = false, -- write all buffers when the current one meets `condition`
|
|
debounce_delay = 135, -- saves the file at most every `debounce_delay` milliseconds
|
|
callbacks = { -- functions to be executed at different intervals
|
|
enabling = nil, -- ran when enabling auto-save
|
|
disabling = nil, -- ran when disabling auto-save
|
|
before_asserting_save = nil, -- ran before checking `condition`
|
|
before_saving = nil, -- ran before doing the actual save
|
|
after_saving = nil -- ran after doing the actual save
|
|
}
|
|
}
|
|
```
|
|
|
|
Additionally you may want to set up a key mapping to toggle auto-save:
|
|
|
|
```lua
|
|
vim.api.nvim_set_keymap("n", "<leader>n", ":ASToggle<CR>", {})
|
|
```
|
|
|
|
|
|
|
|
### 🪴 Usage
|
|
|
|
Besides running auto-save at startup (if you have `enabled = true` in your config), you may as well:
|
|
|
|
- `ASToggle`: toggle auto-save
|
|
|
|
|