As the question title mentions. I'm looking to automatically get the file saved as I type in VIM (insert mode).
Is this possible? How to achieve it?
Definition of autosave : a function of a computer program (such as a word processor or spreadsheet) that automatically saves an open file at regular intervals.
The simplest way to both save and quit out of VI or VIM is with a keyboard shortcut ZZ. Note the capitalization, which means the save and quit command is executed by pressing Escape, then holding the Shift key then pressing Z twice, thus: Press the ESC key, then hold the Shift key then press Z twice.
The command to save a file in Vim is :w. To save the file without exiting the editor, switch back to normal mode by pressing Esc, type :w and hit Enter. There is also an update command :up, which writes the buffer to the file only if there are unsaved changes. To save the file under a different name, type :w new_filename and hit Enter.
There is no native support for auto-saving in Vim. But you can use vim-auto-save plugin to perform that. This plugin auto-saves in normal mode only by default, but there is a section in it's README which describes how to configure the plugin to save in insert mode too.
When you launch the Vim editor, you’re in normal mode. In this mode, you can use vim commands and navigate through the file. To type a text, you need to enter the insert mode by pressing the i key.
A "copy" of your file. Yes, swap is held in memory. When Vim reads a file it adds it to RAM. That is both for existing and new (still unsaved files). As swap is saved it is flushed to disk. The HDD. From RAM. With default settings most of your work are saved. That is for every 200 characters entered, or when yo have a 4 second pause.
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.
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.
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