Since your question is about saving files, here's how I do it.
Vim files out of my way
if exists('$SUDO_USER') " no files for root user
set noswapfile
set nobackup
set nowritebackup
set noundofile
set viminfo=
else " I created a tmp folder
set backupdir=$HOME/.vim/tmp/backup//
set directory=$HOME/.vim/tmp/swap//
set undodir=$HOME/.vim/tmp/undo//
set viewdir=$HOME/.vim/tmp/view//
set viminfo+=n$HOME/.vim/tmp/viminfo
endif
The //
is to avoid conflicts: it will create a file based on the path, so 2 files named the same can't conflict here.
Auto write AND read
set autoread
set autowriteall
Save when focus is lost, load when focus is gained
A complement for autowriteall
and autoread
.
augroup FocusAutoReadWrite
au!
au FocusGained,BufEnter * :silent! !
au FocusLost,WinLeave * :silent! w
augroup end
GTK vim and Neovim handle it by default (:h :FocusGained
).
In regular terminal vim, a compatible terminal is needed to get focus events. I use it with tmux
and this extension.
Sorry for telling you to disable your swap files. I thought that's what I do, but I don't. And I don't think you should do it when you can set them up properly...
:h noswapfile
– Biggybi May 6 '20 at 12:46autowrite
comes to help. There're others, more reliable ways to autosave files (check this post). Then, you canautoread
so you'll load changes made to your files. – Biggybi May 6 '20 at 12:52remote_expr()
functions, thus does not work for Neovim (who patched that out I think). – Christian Brabandt May 6 '20 at 14:05