sponsor Vim development Vim logo Vim Book Ad

basic Tip #927: A better autowrite?

 tip karma   Rating 4/7, Viewed by 1634 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   May 10, 2005 5:50      complexity:   basic
author:   Eric Arnold      as of Vim:   5.7


I'm curious whether this is a good idea.  I saw that an "autowrite" was in the "todo.txt" helpful, but wasn't implemented yet, so I did this.


map <leader>aw :call Myautowrite()<CR>

function! Myautowrite()
    if ( !exists( "g:myautowrite" ) )
        let g:myautowrite = 0
    endif

    if ( g:myautowrite == 0 )
        let g:myautowrite = 1

        exec "aug myautowrite"
        exec "au BufLeave * silent! update"
        exec "au FocusLost * silent! update"
        exec "aug end"
        exec "echo 'Auto-update-all is ON'"
    else
        let g:myautowrite = 0

        exec "aug myautowrite"
        exec "au!"
        exec "aug end"
        exec "echo 'Auto-update-all is OFF'"
    endif

endfunction

 rate this tip  Life Changing Helpful Unfulfilling 

<< QT Help from Vim | q: and q/ >>

Additional Notes

Anonymous, May 22, 2005 7:36
:help 'aw'
:help 'awa'
Anonymous, June 30, 2005 11:55
what does this offer over the standard aw option!!??
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo