I'm constantly doing this in vim: [do something in insert or normal mode], Esc, :ws
I do this hundreds of times a day. Instead, I'd like to lose the habit and have vim save to file immediately after any change to buffer.
Everything is running off an SSD so I don't expect performance to be an issue.
Press Esc key and type :w to save a file in vim. One can press Esc and type :wq to save changes to a file and exit from vim.
Save file in vim by pressing ESC and ZZ. This will save and exit in vim or vi text editor running on Unix or Linux.
The CursorHold
and CursorHoldI
might help. According to docs:
|CursorHold| the user doesn't press a key for a while
|CursorHoldI| the user doesn't press a key for a while in Insert mode
Those events fire only once after inactivity and depend on updatetime
variable (default: 4000ms). So you can:
:au CursorHold <buffer> :update
Which will update current buffer file (i.e. save only if modified) after default 4 seconds of inactivity in Normal mode.
Add autocommand for CursorHoldI
if you want to get the same behavior in Insert mode.
Here's a little function for autosave: http://vim.wikia.com/wiki/Auto-save_current_buffer_periodically
Add this simple mapping to your ~/.vimrc
:
inoremap <Esc> <Esc>:w<CR>
to write the current buffer automatically on each <Esc>
in INSERT mode.
Not that I know of, other than coding it (check out the VIM Wiki for a starting point). VIMs swap file almost does what you are asking, for recovery purposes.
From the VIM man page;
The swap file is updated after typing 200 characters or when you have not typed anything for four seconds
Seems like that would catch most quirks. Is there some specific problem you are trying to avoid?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With