Sunday, August 25, 2019

A script which let vim auto-save files.

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 <hongyi.zhao@gmail.com>
Institute of Semiconductors, Chinese Academy of Sciences
GnuPG DSA: 0xD108493

--
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAGP6POJPj4QjaG0BDaL17_p0U8ziw3rLhmoMzOWx7_Zjrn6mtA%40mail.gmail.com.

No comments: