Giter Site home page Giter Site logo

techcaotri / auto-save.nvim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pocco81/auto-save.nvim

0.0 0.0 0.0 203 KB

๐Ÿงถ Automatically save your changes in NeoVim

License: GNU General Public License v3.0

Lua 95.64% Makefile 4.36%

auto-save.nvim's Introduction

๐Ÿงถ auto-save.nvim

Automatically save your changes in NeoVim

Stars Issues Repo Size

ย 

๐Ÿ“ข 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:

Packer.nvim
use({
	"Pocco81/auto-save.nvim",
	config = function()
		 require("auto-save").setup {
			-- your config goes here
			-- or just leave it empty :)
		 }
	end,
})
vim-plug
Plug 'Pocco81/auto-save.nvim'
lua << EOF
	require("auto-save").setup {
		-- your config goes here
		-- or just leave it empty :)
	}
EOF

ย 

โš™๏ธ Configuration

auto-save comes with the following defaults:

{
    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:

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

ย 

auto-save.nvim's People

Contributors

pocco81 avatar refractalize avatar xxiaoa avatar charludo avatar sakkke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.