2

How to autosave in Vim using no plugin?

I have found the following post:

Auto-save in VIM as you type

which gives the following answer:

autocmd TextChanged,TextChangedI <buffer> silent write

which works perfectly except that when I put that in my .vimrc it doesn't work, so how can I put that line in my .vimrc such that it works everytime I open Vim ?

EDIT: It seems putting that line in .vimrc works WHEN I DON'T USE A SESSION !

So I will rephrase my question:

How can I get the above work in combination with mksession to open preconfigured session in Vim using vim -S ?

user395980
  • 356
  • 1
  • 8

1 Answers1

5

As stated in the comments by D. Ben Knoble, you need to use * instead of <buffer>:

autocmd TextChanged,TextChangedI * silent write
wfehr
  • 2,185
  • 10
  • 21