How to make vim automatically save only current buffer when focus is lost, not all files as described here http://vim.wikia.com/wiki/Auto_save_files_when_focus_is_lost
Based on your comments I can say that you have wrong question: you want not to “save only current buffer when focus is lost” (focus tends to have a meaning of “currently focused window”), but to “write buffer when switching to another one: when it is no longer in your focus of attention”. To complete this you may use
augroup AutoWrite
autocmd! BufLeave * :update
augroup END
, maybe combined with
set autowrite
and
set autowriteall
(sets of situations where first and second two variants are triggered intersect, but neither is a superset of another one).
Instead of :wa
(write all), use :w
.
-
@milushov Wondering whether you are using terminal vim. If yes, forget about this idea or use gvim instead. – ZyX Jan 7 '13 at 18:51
-
@ZyX i use gvim, btw there is my vimrc file - github.com/milushov/dotvim/blob/master/vimrc#L275 – milushov Jan 7 '13 at 18:55
-
1
-
1@milushov Toggle buffers? This (
FocusLost
) is event for the case when you switch from GVim window to something else (e.g. browser or terminal). For switching between GVim windows you should useWinLeave
, for switching between GVim tabs useTabLeave
(not really needed asWinLeave
is launched prior to this) andBufLeave
for really toggling buffers (launched beforeWinLeave
orTabLeave
). You are likely needing the latter in place ofFocusLost
. Or, maybeFocusLost,BufLeave
. – ZyX Jan 7 '13 at 19:09 -
1
Also you can try this
set updatetime=1000
autocmd CursorHoldI * silent w
just put it in your .vimrc