← Back to context

Comment by kazinator

4 years ago

Vim doesn't do it "well" with the settings above, just "good enough". The time stamp suffix is calculated just once when you start Vim, set in the global backupext option. If we :e edit files in an existing Vim session, they all get backups with that time stamp. It needs to be calculated as a buffer-specific value of that option, if there is such a thing, on every new edit.

I just found that the Vim manual recommends, right in the doc for backupext, the use of the BufWritePre hook instead, so:

  :au BufWritePre * let &backupext=("." . strftime("%y-%m-%d.%H:%M:%S"))

This has the right effect that every time you save with :w, a new backup is made of the previous contents.