Why is vim leaving temporary file versions all over the place?

9

2

First of all I assume those files ending with "~" which are created by vim when editing a file are indeed serving the purpose of temporary backups while editing.

But every time I open a file with vim and close it (:wq) I afterwards find such a file~. Why is vim not cleaning up? I assume there is something not correctly configured.

Raffael

Posted 2014-03-17T18:31:06.073

Reputation: 1 029

2They are not temporary backup files; they are the previous versions of the files. In a directory under version control they tend to become a nuisance. – Thorbjørn Ravn Andersen – 2014-03-18T07:55:41.233

Answers

19

You can disable backup files putting this line in your vimrc file:

set nobackup

But if you still want to backup your files, centralize it to a directory with:

set backupdir=~/tmp

for example.

periket2000

Posted 2014-03-17T18:31:06.073

Reputation: 559

1thanks - but is this really the intended behaviour? I mean even when I do not change anything in the file those files are created and remain after closing vim. I assume (intuitively) that vim must be able to get rid of those files when closing!? I would not like to disable it as it might be of use when vim crashes. The backupdir-solution seems to be a good compromise though – Raffael – 2014-03-17T18:38:20.320

Yes; They are backup files; the default behavior is to create those backup files. – Ramhound – 2014-03-17T18:43:42.140

@Яaffael, the backup option is off by default, you should read the doc before enabling an option. – romainl – 2014-03-17T21:26:37.277

2@Яaffael The .swp files are used when vim crashes, not the backups – Izkata – 2014-03-17T21:42:22.197

1The backup files are created when you write the file. If you haven't changed anything, why did you write it? If you just habitually do :w maybe you could do :up instead which will only save if there are changes. – Ben – 2014-03-18T02:15:11.827

5

First of all I assume those files […] are indeed serving the purpose of temporary backups while editing.

No. They are non-temporary backups made when saving.

The temporary files created while editing are (on UNIX-alike platforms) named .wibble.swp (for a file named wibble).

:help backup
in vim itself gives you the gen on the former, including the rules for when backup files are created and when they are not.
:help swap
gives you the gen on the latter.

JdeBP

Posted 2014-03-17T18:31:06.073

Reputation: 23 855

>

  • what does "gen" mean? 2) what purpose do those non-temporary backups serve?
  • < – Raffael – 2014-03-17T22:19:05.367

    Allgemeine Informationen. – JdeBP – 2014-03-17T22:34:54.330

    2With that link, you force readers to look through definitions until one makes sense. Why not just say it's an informal world for "information"? – Andrew Cheong – 2014-03-18T05:24:27.843