On 10/13/06, David Schweikert <[EMAIL PROTECTED]> wrote:
Would it be possible to make Vim overwrite a backup file only if
the buffer was actually modified? Look at the following scenario:

1. I edit file foobar.txt, make some change and save it.

   -> the backup file foobar.txt~ is created

2. I edit again foobar.txt, but this time I don't make any change.
   I do however write the file with ':w' by mistake...

   -> the backup file foobar.txt~ is replaced and both files
      have now the same content.

If there is some problem in replacing the current behaviour, could it
maybe be an option?

You have several options.
1) Try "savevers" plugin
http://www.vim.org/scripts/script.php?script_id=89
It saves numbered version at each save, in the directory you specify
(I use ~/tmp). This is much more useful than single ~ backup file.

2) You can take up to using :up rather than :w. :up command
only writes file if it was mofified.

3) You can use autocommands to avoid saving the buffer if  buffer is
not modified.
I'm not sure at the moment how to achieve it in one-liner; the
following works but gives
ugly message when buffer is not modified:
   au BufWritePre * if !&modified | throw "Nothing to save" | endif

4) You can use tip http://www.vim.org/tips/tip.php?tip_id=1285
to remap :w to :up :

cabbrev w <c-R>=(getcmdtype()==':' && getcmdpos()==1 ? 'up' : 'w')<cr>

Yakov

Reply via email to