Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
1  
They 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 Mar 18 '14 at 7:55
up vote 17 down vote accepted

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.

share|improve this answer
1  
thanks - 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 Mar 17 '14 at 18:38
    
Yes; They are backup files; the default behavior is to create those backup files. – Ramhound Mar 17 '14 at 18:43
    
@Яaffael, the backup option is off by default, you should read the doc before enabling an option. – romainl Mar 17 '14 at 21:26
2  
@Яaffael The .swp files are used when vim crashes, not the backups – Izkata Mar 17 '14 at 21:42
1  
The 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 Mar 18 '14 at 2:15

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.

share|improve this answer
    
1) what does "gen" mean? 2) what purpose do those non-temporary backups serve? – Raffael Mar 17 '14 at 22:19
    
Allgemeine Informationen. – JdeBP Mar 17 '14 at 22:34
1  
With 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 Mar 18 '14 at 5:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .