A script which let vim auto-save files.

162 views
Skip to first unread message

Hongyi Zhao

unread,
Aug 26, 2019, 2:49:48 AM8/26/19
to vim...@googlegroups.com
Hi,

In order to let vim auto-save files, I tried the follwing plugin:

https://github.com/907th/vim-auto-save

But, I found that sometimes it will not take effect and I don't know
what's the conflicts in my vim configurations.

So I want to find other methods to do this thing and I find the following one:

https://vi.stackexchange.com/questions/74/is-it-possible-to-make-vim-auto-save-files

And based on the above method given by dash-tom-bang, I revised into
the following code:

------------
if exists(':keeppatterns')
let s:keeppatterns = 'keeppatterns '
else
let s:keeppatterns = ''
endif

augroup AutoSaveGroup
" :help file-pattern has some info,
" but some of it is is buried in the PATTERNS section of usr_40.txt
"let s:autoPattern =
"*.{c,h,[ch]pp,[acjt]s,inl,cg,cgfx,fx,py,bat,cmd,jam,vim,yml,yaml,vsprops,erb,rb,html,htm},SCons*,*vimrc"

let s:autoPattern = "*"


autocmd!
execute "autocmd FocusLost" s:autoPattern "silent! wall"
execute "autocmd BufWritePre" s:autoPattern s:keeppatterns .
'call FixFormatting(expand("<afile>"))'

execute "autocmd FileChangedRO" s:autoPattern "silent !p4 edit %:p"
execute "autocmd FileChangedRO" s:autoPattern "write!"

autocmd FocusLost * silent! wall
augroup END
------------

I'm a newbie on vimscripts, and till now, it seems the above script
works smoothly.

I want to know is there any bugs/revisions/enhancenments on the above script?

Thanks in advance.
--
Hongsheng Zhao <hongy...@gmail.com>
Institute of Semiconductors, Chinese Academy of Sciences
GnuPG DSA: 0xD108493

Christian Brabandt

unread,
Aug 26, 2019, 4:50:26 AM8/26/19
to vim...@googlegroups.com

On Mo, 26 Aug 2019, Hongyi Zhao wrote:

> Hi,
>
> In order to let vim auto-save files, I tried the follwing plugin:
>
> https://github.com/907th/vim-auto-save

as far as I remember that script depends on Vims autocommands to do it's
work. Nowadays with a modern vim you can instead make use of timers,
that work a bit more reliable. My autosave plugin uses this:
https://github.com/chrisbra/vim-autosave


Best,
Christian
--
Stilblüten aus Schreiben von Versicherungsnehmern:
Zunächst sagte ich der Polizei, ich sei nicht verletzt, aber als ich
den Hut abnahm, bemerkte ich den Schädelbruch.

Hongyi Zhao

unread,
Aug 26, 2019, 6:03:54 AM8/26/19
to vim...@googlegroups.com
Christian Brabandt <cbl...@256bit.org> 于2019年8月26日周一 下午4:50写道:
>
>
> On Mo, 26 Aug 2019, Hongyi Zhao wrote:
>
> > Hi,
> >
> > In order to let vim auto-save files, I tried the follwing plugin:
> >
> > https://github.com/907th/vim-auto-save
>
> as far as I remember that script depends on Vims autocommands to do it's
> work. Nowadays with a modern vim you can instead make use of timers,
> that work a bit more reliable. My autosave plugin uses this:
> https://github.com/chrisbra/vim-autosave

Thanks for your reply. I try your autosave plugin, but it seems id
doesn't work for my case.

I want to the save into the original opened buffer/file instead of
into a backup file.

Regards

>
>
> Best,
> Christian
> --
> Stilblüten aus Schreiben von Versicherungsnehmern:
> Zunächst sagte ich der Polizei, ich sei nicht verletzt, aber als ich
> den Hut abnahm, bemerkte ich den Schädelbruch.
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20190826085019.GN10736%40256bit.org.

Hongyi Zhao

unread,
Aug 26, 2019, 6:32:00 PM8/26/19
to vim...@googlegroups.com
Hongyi Zhao <hongy...@gmail.com> 于2019年8月26日周一 下午6:03写道:
>
> Christian Brabandt <cbl...@256bit.org> 于2019年8月26日周一 下午4:50写道:
> >
> >
> > On Mo, 26 Aug 2019, Hongyi Zhao wrote:
> >
> > > Hi,
> > >
> > > In order to let vim auto-save files, I tried the follwing plugin:
> > >
> > > https://github.com/907th/vim-auto-save
> >
> > as far as I remember that script depends on Vims autocommands to do it's
> > work. Nowadays with a modern vim you can instead make use of timers,
> > that work a bit more reliable. My autosave plugin uses this:
> > https://github.com/chrisbra/vim-autosave

I still cannot understand, even with one line as follows will do the trick:

autocmd TextChanged,TextChangedI * silent! wall

Why you and others still try to write plugin for this type of job?

Regards

Christian Brabandt

unread,
Aug 27, 2019, 5:15:37 AM8/27/19
to vim...@googlegroups.com

On Di, 27 Aug 2019, Hongyi Zhao wrote:

> I still cannot understand, even with one line as follows will do the trick:
>
> autocmd TextChanged,TextChangedI * silent! wall
>
> Why you and others still try to write plugin for this type of job?

If you really want to know, I suggest reading the plugin source to know
why it takes many (or not so many) extra steps.

BEst,
Christian
--
Wie man sein Kind nicht nennen sollte:
Bill Anz
Reply all
Reply to author
Forward
0 new messages