views:

283

answers:

6

What is the purpose of the X~ files? And if its unnecessary, is there a way to prevent Vim from creating one?

+7  A: 

This is a backup file that contains a copy of the previous revision of the file.

You can change this behavior by adding a line to the end of your .vimrc file:

set nobackup
eleven81
+6  A: 

its a backup file, every time you save while modifying something it will create one. There's an option to turn it off.

See here from the vim faq

yx
+3  A: 

Turn it off using

:se nobackup

You can also tell it to put the backup file in a different location by using:

:se directory=c:\temp
John Weldon
+2  A: 

They are backup files. Maybe :set nowritebackup will turn off this feature.

Andrea Francia
+3  A: 

Vim is creating backup files automatically. To turn it off you have to add the following line to your .vimrc config file:

set nobackup

wr
+4  A: 

What I personally do is that I create a folder $HOME/.vim/backupfiles that will contain all my backup files, instead of leaving them all scattered around.

My .vimrc contains the following:

set backupdir=~/.vim/backupfiles,~/tmp,.

This way you have the protection of backup files but avoid the littering of your folders with *~ files.

Jorge Gajon
This could cause name-clashes if you have files with the same name. I don't know if vim resolves this, or even if this is likely, but it could happen.
sykora
@sykora, yes it does happen, if you edit two files with the same name, the older backup will be rewritten, but I've never had an issue with that, and personally I think it's a good trade off.
Jorge Gajon