2

For example, I'll use VIM to code a Python script and then save the file.

When I navigate to the directory I saved in and use the ls command, up comes:

test_file.py
test_file.py~

Are these backup files?

user
  • 403
  • 1
  • 4
  • 7
  • 4
    Yes those are backup files. – Rohit Jain Aug 12 '13 at 22:54
  • 1
    @RohitJain I've never seen such files generated (permanently) by vim.. I guess the file is backup file from gedit or another text editor – hek2mgl Aug 12 '13 at 22:56
  • @RohitJain it's quite annoying how cluttered it can become if I don't periodically delete these. Is there a way to disable them? Or have them save to a different directory? – user Aug 12 '13 at 22:58
  • This question appears to be off-topic because it belongs to [Unix & Linux](http://unix.stackexchange.com/) – Rohit Jain Aug 12 '13 at 23:00
  • @user can you show your `~/.vimrc` ? – hek2mgl Aug 12 '13 at 23:00
  • @hek2mgl my vimrc is completely default (other than four lines added to change the spacing/indents to suit Python specifically). – user Aug 12 '13 at 23:02

3 Answers3

1

Yes, the files that end with the tilde (~) are backups of files right before you edited it.

These backups will be handy if you experience a crash. If you want to save them in another directory, you can add this to your .vimrc:

set backupdir=~/vim_tmp,.
set directory=~/vim_tmp,.

where ~/vim_tmp is the directory you want to store your backup files.

jh314
  • 27,144
  • 16
  • 62
  • 82
  • can you show a documentation reference? *my* vim don't create `~` files – hek2mgl Aug 12 '13 at 22:59
  • Interesting, I just tested it out and you're right, it's a backup of your last save. Do you know if there is a way to change which directory VIM saves these backups to? It can get really messy if I let them pile up. – user Aug 12 '13 at 23:00
  • Sure, I just added it to my answer. – jh314 Aug 12 '13 at 23:01
  • @jh314 Why does my - ubuntu 12.04 - vim 7.2 - don't create such files? (have almost complete default vimrc as well) – hek2mgl Aug 12 '13 at 23:02
1

Yes, they are automatic backup files.
I have this in my .vimrc:

set writebackup " Write a backup when saving a file...
set nobackup    " ...but delete the backup upon successful completion of the save.

Here are the possiblities:

'backup' 'writebackup'  action
off      off            no backup made
off      on             backup current file, deleted afterwards (default)
on       off            delete old backup, backup current file
on       on             delete old backup, backup current file

I also have
set backupdir=$VIM/backup
so that all of my backup files are in the same location, rather than the location of the original file.
See :help backup for more.

Edward
  • 1,000
  • 5
  • 16
1

Yes, they are vim backup files. (if you use default backup file extension)

To disable backup in vim:

set nobk
set nowb

you may want to check :h 'bk' and :h 'wb' for detail.

@hek2mgl

if one uses the default backup file name extension, it is tilde ~. for detail you could check :h 'bex':

'backupext' 'bex'   string  (default "~", for VMS: "_")
            global
            {not in Vi}
    String which is appended to a file name to make the name of the
    backup file. 
Kent
  • 189,393
  • 32
  • 233
  • 301