Auto-save in VIM as you type
This will handle read-only buffers (like netrw) and undetected filetypes. Using TextChangedI instead of InsertLeave seems to cause a write for every character typed in insert mode, which may or may not be what you want.
augroup autosave
autocmd!
autocmd BufRead * if &filetype == "" | setlocal ft=text | endif
autocmd FileType * autocmd TextChanged,InsertLeave <buffer> if &readonly == 0 | silent write | endif
augroup END
You can use AutoSave plugin to perform that:
https://github.com/907th/vim-auto-save
Please notice that AutoSave is disabled by default, run :AutoSaveToggle
to enable/disable it.
I recommend to save the buffer whenever text is changed:
autocmd TextChanged,TextChangedI <buffer> silent write
I found it here. It works for me.
Note (thanks to @Kevin): Unfortunately, it will result in errors if you open vim without opening a file because vim will try to save the text you type but won't have where.