Giter VIP home page Giter VIP logo

vim-auto-save's Introduction

Call for Maintainer

Dear users of this plugin! Sorry, but I no longer maintain it! If someone of you are interested in maintaining it, please, contact me and I will add you as a contributor.

Description

AutoSave - automatically saves changes to disk without having to use :w (or any binding to it) every time a buffer has been modified or based on your preferred events.

Inspired by the same feature in RubyMine text editor.

By default AutoSave will save every time something has been changed in normal mode and when the user leaves insert mode. This configuration is a mix between "save as often as possible" and "try to avoid breaking other plugins that depend on filewrite-events".

Installation

Use vundle or download packaged version from vim.org.

Usage

AutoSave is disabled by default, run :AutoSaveToggle to enable/disable it.

Options

Enable on Startup

If you want the plugin to be enabled on startup use the g:auto_save option.

" .vimrc
let g:auto_save = 1  " enable AutoSave on Vim startup

It's also possible to override global g:auto_save value individually per buffer or window. For example, if you have auto save enabled globally, you can opt out some files. And vice versa, opt in some files, when you have auto save disabled globally.

let g:auto_save = 0
augroup ft_markdown
  au!
  au FileType markdown let b:auto_save = 1
augroup END

Silent

AutoSave will display on the status line on each auto-save by default:

(AutoSave) saved at 08:40:55

You can silence the display with the g:auto_save_silent option:

" .vimrc
let g:auto_save_silent = 1  " do not display the auto-save notification

Events

The events on which AutoSave will perform a save can be adjusted using the g:auto_save_events option. Using InsertLeave and TextChanged only, the default, will save on every change in normal mode and every time you leave insert mode.

" .vimrc
let g:auto_save_events = ["InsertLeave", "TextChanged"]

Other events you may want to use:

  • TextChangedI will save after a change was made to the text in the current buffer in insert mode.
  • CursorHold will save every amount of milliseconds as defined in the updatetime option in normal mode.
  • CursorHoldI will do the same thing in insert mode.
  • CompleteDone will also trigger a save after every completion event.

Some of these commands may not be available, depending on your Vim installation. See the autocommands overview for a complete listing (:h autocommand-events).

Warning! Be advised to be careful with the updatetime option since it has shown to cause problems when set too small. 200 seems already to be too small to work with certain other plugins. Use 1000 for a more conservative setting.

(Pre/Post)save Hooks

If you need an autosave hook (such as generating tags post-save, or aborting the save earlier) then use g:auto_save_postsave_hook or g:auto_save_presave_hook options:

" .vimrc

" This will run :TagsGenerate after each save
let g:auto_save_postsave_hook = 'TagsGenerate'

" This will run AbortIfNotGitDirectory function before each save
let g:auto_save_presave_hook = 'call AbortIfNotGitDirectory()'

" Example hook from vim-auto-save-git-hook plugin
function! AbortIfNotGitDirectory()
  if ...
    let g:auto_save_abort = 0
  else
    let g:auto_save_abort = 1
  endif
endfunction

Write to All Buffers

By default only the current buffer is written (like :w). You can choose that all buffers are written on autosave using the g:auto_save_write_all_buffers option (like :wa).

" .vimrc
let g:auto_save_write_all_buffers = 1  " write all open buffers as if you would use :wa

Development

The doc/auto-save.txt is a converted version of the README.md. Don't edit it directly. Instead install the md2vim and run the update_doc_from_readme.sh script.

Contribution or Bug Report

Development is made in 907th/vim-auto-save repo. Please, report any bugs and/or suggestions there. Any contrubution is welcomed!

License

Distributed under the MIT License (see LICENSE.txt).

Copyright (c) 2013-2021 Aleksei Chernenkov

vim-auto-save's People

Contributors

907th avatar aaronjensen avatar ammarnajjar avatar inside avatar kqvanity avatar leonardinius avatar markjanssenpon avatar rdolgushin avatar rsepassi avatar samoshkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-auto-save's Issues

How to activate auto-save per filetype?

Hi,
I can't seem to make it toggle for ruby files only.
I tried:

augroup auto_save_for_ruby
  autocmd!
  autocmd Filetype *.rb :AutoSaveToggle()
augroup END

Any suggestion on how to make this happen?
—Alberto

Breaks CTRL-X Mode

I'm using gvim on Windows. I used Vundle to install the plugin from here. When this plugin is loaded, if I try to enter ^X mode by pressing CTRL-X in INSERT mode, it immediately exits back into the general INSERT mode. If I comment out the line Plugin 'vim-scripts/vim-auto-save' and change it to " Plugin 'vim-scripts/vim-auto-save' then I can enter and stay in ^X mode. I'm not completely familiar with VimL for plugins otherwise I would try toggling some of the g: variables. Could you tell me if there is any fix for this?

Undo not working on go files when auto-save is enabled.

First off - this is a great plugin and always ensures all my buffers are in sync with the disk.

However with go files (I use fatih/vim-go plugin), whenever I do any change, the auto-save plugin saves my work and the go plugins run a sanity check and linting.

Post that, I am not able to perform any undo action.
Undo is working absolutely fine in all other files, just not with go files.

Here is my vimrc

packadd! matchit
set ruler
filetype plugin indent on
filetype plugin on
set nocompatible
set history=100
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
set autowrite
set tabstop=4
set softtabstop=4
set expandtab
set showcmd
filetype indent on
set wildmenu
set showmatch
set undofile
set undodir=/Users/akshay/.vim/undo
if empty(glob('/Users/akshay/.vim/autoload/plug.vim'))
silent !curl -fLo /Users/akshay/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'junegunn/vim-plug'
Plug 'dkarter/bullets.vim'
Plug 'fatih/vim-go'
Plug 'tpope/vim-fugitive'
Plug '907th/vim-auto-save'
Plug 'vim-airline/vim-airline'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'ctrlpvim/ctrlp.vim'
call plug#end()

let mapleader=","
nnoremap :nohlsearch
map :cnext
map :cprevious
map :GoDecls
map :GoDeclsDir
nnoremap a :cclose
nnoremap al :GoAlternate
nnoremap e :GoTest
nnoremap f :GoTestFunc
nnoremap gs :Gstatus
nnoremap sr :source~/.vimrc
nnoremap t

autocmd vimenter * NERDTree
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

function! s:build_go_files()
let l:file = expand('%')
if l:file =# '^\f+_test.go$'
call go#test#Test(0, 1)
elseif l:file =
# '^\f+.go$'
call go#cmd#Build(0)
endif
endfunction

autocmd FileType go nmap b :call build_go_files()
autocmd FileType go nmap c (go-coverage-toggle)
autocmd FileType go nmap r (go-run)
autocmd FileType go nmap e (go-test)
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
let g:auto_save=1
let g:auto_save_no_updatetime = 1
let g:auto_save_write_all_buffers=1
let g:go_fmt_command = "goimports"
let g:go_auto_type_info = 1
let g:go_auto_sameids = 1
let g:go_list_type = "quickfix"
`

Sample go file

package main
import (
"os"
"text/template"
)
type Test struct {
Name string
}
func main() {
tmp := template.New("SMS").Option("missingkey=zero").Delims("${", "}")
tmp, _ = tmp.Parse("${.otp} is your OTP for ${.company} Freight")
par := make(map[string]string)
par["otp"] = "1234"
tmp.Execute(os.Stdout, par)
}

maybe make CursorHoldI optional?

For things that are watched by fs watchers an autosave while typing is a little brutal and can cause them to miss changes. I wonder if CursorHoldI could be optional.

Installation directions for people who don't have vundle

Firstly thanks for the plugin 👍🏽

It would be nice to add installation directions for users who don't have vundle.
Plus it would be nice for new users to configure the setup easily, not everyone used vundle, plug etc

For e.g for neovim users :

  1. Create the following path inside your nvim config folder & cd into it
   mkdir -p ~/.config/nvim/pack/vim-auto-save/start && cd $_
  1. Clone vim-auto-save
    git clone https://github.com/907th/vim-auto-save.git
  1. Change config in your init.vim file if needed and it is done!

Other methods

Let me know if this is what you want, I will send a PR

per buffer option ?

Is it possible to enable autosave on a per buffer basis ?

I like to enable it for python but would prefer not saving buffers with other ft.
Thanks for the plugin.

Don't work with "Ctrl + C" way to leave insert mode

Hello,

Thank you for this supplement to Vim which I use every day !
Recently, to try to improve keyboard typing comfort, I left the "insert" mode by "Ctrl + c" instead of "escape" touch.
In this case, it seems that auto-save does not work. Is there a way around the problem?
Thank you in advance for your answer.

Isn't working as desired with TextChangedI

I added TextChangedI as an event. vim-auto-save abruptly shifts cursor position to the left while inserting text. Guess it is a escape and entering insert mode with i issue.

add new feature--auto_save_inteval option is great?

this vim plugin works so cool,it auto saves changes on the fly,but some times it's not the action we want,for example: misstroke the keyboard carelessly would also auto save the error changese which we do not want when in insert mode,and if add the auto_save_interval options it would mitigate it's influnce.

don't touch file if no changes has been made

Since I have enabled this pluggin in vim 8.0 just looking at some files causes timestamps to be updated. This means various compilation occur needlessly for me. There should be a check that the file has actually changed when saving. I have setup the plugin with CursorHold & CursorHoldI, I don't know if that matters.

Thank you.

I don't know very well the vim language. It looks like it it does check if file was modified but calls save regardless

https://github.com/907th/vim-auto-save/blob/master/plugin/AutoSave.vim#L74

perhaps that line should be in the if block checking if it was modified.

Adjusting default options configuration for highest utility

I know the plugin is based on the Rubymine behavior which saves automatically every 200ms.
But vim feels different then Rubymine.

A switch to insert mode is atomic for me. I change something and am back in normal mode as soon as possible. So a save during that time is unnecessary and even disadvantages for me, because it disrupts my writing and splits my changes into multiple which are then not represented in my undo/repeat list as they would be in vim without vim-auto-save.

200 ms update time in normal mode often causes problems for me with other plugins and syntax highlighting. So I increase it or switch it off completely. But at the same time I want to be sure, that as soon as I use the file (read it with another program, execute it) the file is in the most recent state. So I add the auto save event TextChanged which operates in normal mode and saves on every text change.

I would like to know how other people are using vim-auto-save. And whether it would make sense to adjust the default options based on that, to have an installation which works for as many people out of the box as possible.

what is the interval after which autosave will work?

I am using Neovim latest version (version 0.3.2). It seems that I can not see the autosave hint on the status bar right now. My settings for autosave:

let g:autosave = 1
let g:auto_save_events = ["InsertLeave", "TextChanged"]
let g:auto_save_silent = 0

If I leave the insert mode, how much time will it take for autosave to work? Or, will it work immediately after I exit insert mode?

Edit: It seems that the above setting is not enough. I have manually use :AutoSaveToggle command to activate autosave. Any idea what is wrong?

Autosave only after the file is written

Is there any setting that allows me to make it so vim-auto-save only starts autosaves after the file is written (manually using :w)?

I want this kind of setting because when I enter a new file using vim, I don't want vim-auto-save to immediately save after opening, because I might want to not keep the new file.
My current settings for vim-auto-save is only let g:auto_save = 1

Software:
Ubuntu, wsl2
nvim

Seems to stop Syntastic from working

When using Syntastic, normally any configured Syntastic checks are run automatically on saving a file.

With vim-auto-save enabled, however, the Syntastic checks don't seem to fire. Only when using :w to manually save a file with vim-auto-save enabled, or when manually executing :SyntasticCheck do we get a syntax check.

Strange behaviour with 'CompleteDone'

With let g:auto_save_events = ['CompleteDone'] my cursor jumps to the begining of the paragraph / block when I press Shift :. The strange thing is that it happens only when inserting a breakline in the first line and then typing some text ending by ":" (see attached gif for example)... I'm not really sure what to make of that...
anim

Feature request: settings to exclude some files

Hey, thanks for nice plugin!

I have autocmd command for auto sourcing my vimrc. And when the plugin is saving file I'm getting my vim unnecessary frozen during sourcing the config..

autocmd bufwritepost $MYVIMRC source $MYVIMRC

It would be nice to have a setting to ignore/exclude some files, smth like this:

let g:auto_save_files_ignore = [$MYVIMRC]

Btw I have these settings:

let g:auto_save = 1
" https://github.com/907th/vim-auto-save/issues/53#issuecomment-571819789
let g:auto_save_events = ["CursorHold"]
set updatetime=300

Btw2 I can donate few dollars for this feature!

Undo list is modified for every repetition of a macro

First-off: Great plugin! Auto-saving is a revelation.

I've run into a minor annoyance: Let's say I record a macro with qqAhello<Esc>q. Then, I run the macro 22 times with 22@q.

Normally (with auto-save disabled), running the macro 22 times as I did is counted as one change. So I can undo all of it with a single u.

With auto-save enabled, each of the 22 runs is counted as a separate change. I would have to press u 22 times or 22u to get back to where I was.

Not sure what the best way to deal with this is or if it should even be dealt with. Just want to bring it to your attention.

Any way to save file asynchronously?

Hello, I use InsertLeave to trigger the autosave function. However, the cursor always stuck when I leave insert mode.

Since vim 8 and neovim use job_start() and jobstart() to run command in asynchronous way, so I'm wondering is there any way in asynchronous can help for this problem?

Normal mode only?

Saving on any change in insert mode can be quite a lot and it leads to some integrations/plugins flickering. Wouldn't it make more sense to only auto save once I'm back in normal mode? Could this be a configurable option or even the default? Usually, in Vim, going into insert mode, changing multiple things and then going back into normal mode only counts as one change so I would also expect this plugin to only save after I've gone back into normal mode.

Any feedback?

Change from 24 hour time to AM/PM

I know this is kinda small, but I was wondering if there is a way for vim-auto-save to tell you what time it auto-saved in AM/PM time.

Duplicate entry is created in undo history

This duplicate entry is added after an InsertLeave and after the user moves the cursor.

To reproduce:

  1. Enter insert-mode.

  2. Type anything.

  3. Exit insert mode.

    • Autosave is triggered and undo history is updated, as expected.
  4. Move the cursor using any motion.

    • Undo list is updated again with no actual diff, which is not expected.

Here is an example below. I am using undotree to visualize the undo history.
example

Don't attempt to save files with No file name

With this plugin installed if you simply open vim and type, auto-save will attempt to save the buffer even though attempting this will result in an error, and in my case a prompt to continue. It'd be nice if there was an option to disable attempted saves to files with no name.

Error detected while processing CursorHold Auto commands for "*":
E32: No file name
Press ENTER or type command to continue

TextChanged Error

receiving this error:

zsh 1796 [1] % vi .vim/bundle/vim-auto-save/plugin/AutoSave.vim
Error detected while processing /Users/toddbush/.vim/bundle/vim-auto-save/plugin/AutoSave.vim:
line 46:
E216: No such group or event: TextChanged * nested call AutoSave()
Press ENTER or type command to continue

vim version:

zsh 1796 [1] % vi --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jun 14 2016 16:06:49)
Compiled by [email protected]
Normal version without GUI. Features included (+) or not (-):
-arabic +autocmd -balloon_eval -browse +builtin_terms +byte_offset +cindent
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
-conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs
-dnd -ebcdic -emacs_tags +eval +ex_extra +extra_search -farsi +file_in_path
+find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv
+insert_expand +jumplist -keymap -langmap +libcall +linebreak +lispindent
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape
-mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm -mouse_sysmouse
+mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg -osfiletype
+path_extra -perl +persistent_undo +postscript +printer -profile +python/dyn
-python3 +quickfix +reltime -rightleft +ruby/dyn +scrollbind +signs
+smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
-toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
-xterm_clipboard -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -D_FORTIFY_SOURCE=0 -Iproto -DHAVE_CONFIG_H -arch i386 -arch x86_64 -g -Os -pipe
Linking: gcc -arch i386 -arch x86_64 -o vim -lncurses

Error while opening fuzzy finder listing buffer

I've set the autosave to get fired when switching window, however if i happened to have an opened fuzzy finder i.e. non-writable listing buffer, then the following error message would pop up.

Error detected while processing function terminus#private#term_focus_lost[2]..FocusLost Autocommands for "*"..function AutoSave[26]..DoSave:
Line   4:
E565: Not allowed to change text or change window: buffer 106

I know that it's just an edge case, but improvements are always welcome (Unless it'd compromise something else).

Throttling / batching for InsertLeave and TextChanged

Hi! It'd be great to have an option to enable throttling when having this config

let g:auto_save_events = ["InsertLeave", "TextChanged"]

Context: I use a file watcher tool, and if too many changes are made in a short interval, sometimes it doesn't catch the latest change. If vim-auto-save could batch changes every 500ms, that'd be perfect.

Thank you so much for this awesome piece of software. I couldn't picture myself coding without it.

Breaks vim-surround with vim-repeat

If you have auto save enabled, . no longer works when doing a surround command. For example, if you do a cs'" to change single quotes to double quotes, then hit . to repeat it elsewhere, it does not work. Disabling autosave works.

Offer to help facilitate maintenence

I'd be willing to at least help facilitate contributions to this under the auspices of Preservim, a GitHub org I started back in 2016 or so to help revive some unmaintained but still useful plugins. It started with nerdcommenter,but has grown to cover quite a few from there. We have attracted a handful of maintainers that have pitched in to keep old plugins afloat.

The modus operendi would be to have you join the org, transfer the repo there, stick around as the repo owner, but start a team with maintainer level privileges on the repo and approach anybody who looked like a regular contributor with sound ideas to join. We usually add some basic CI checks to make sure the plugin loads and runs as expected and them limit merges to 1 approving reviewer.

I've been a user of this plugin for many years. I can't promise to do a tone of work on it, but it probably doesn't need a whole lot either. I can help facilitate any PRs or issue triage that people do jump in with and at least get CI stuff running.

If you're interested let me know.

updatetime

You should probably add an option to prevent vim-auto-save from changing the updatetime setting since it's global and affects other plugins as well.

Undo does not work when using this plugin

I'm using NeoVim 0.2 on macOS 10.12.5.

When Using the plugin with default options, I can no longer undo changes made in normal mode (maybe also other changes, but didn't test specifically). When I set leg g:auto_save_events = ["InsertLeave"] it seems to work as expected again.

Is this a known problem or bug? Or can I tweak this with config settings?

Plugin breaks Ctrl-X completion

A minimal .vimrc such as this

set nocompatible              
filetype off                  
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

Plugin '907th/vim-auto-save'

call vundle#end()

will cause <C-x> <C-f> to fail.

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.