25

In my environment, I share vim configuration with other developers (and have my own configuration additions as well) in various .vimrc files. Some places in the environment, I edit a file in vim and automagically a copy of that file with a trailing tilde suffix appears. What vim options control this? I'd like to turn the feature off, as it just clutters up my directories and spoils auto-completion on the command line.

Thanks.

Leonard
  • 13,269
  • 9
  • 45
  • 72
  • 1
    Possible duplicate of [Why does Vim save files with a ~ extension?](http://stackoverflow.com/questions/607435/why-does-vim-save-files-with-a-extension) – törzsmókus Dec 08 '15 at 18:47

4 Answers4

48

If you just want to turn off backups entirely, the :set nobackup suggestion from @GregHewgill is the way to go.

However, I've been saved by Vim's backups often enough that I'd like to recommend an alternative. I have these settings in my .vimrc:

set backupdir-=.
set backupdir^=~/tmp,/tmp

The first line removes the current directory from the backup directory list (to keep the ~ backups out of your working directories). The second tells Vim to attempt to save backups to ~/tmp, or to /tmp if that's not possible. (The paths can be adjusted for your particular environment; I use set backupdir^=$TEMP on Windows, for example.)

In other words, this puts the backup files out of sight (and out of your way), but doesn't turn them off entirely.

Bill Odom
  • 4,143
  • 24
  • 20
  • 2
    Neither this, nor Greg Hewgill's suggestion worked. I'm wondering if there is a .vimrc that gets executed AFTER my .vimrc. Is there a way to tell which .vimrc's got used from within a particular vim session? – Leonard May 19 '10 at 21:49
  • Check :help startup for the long explanation of what files vim reads when it starts. – speshak Jul 01 '10 at 22:02
  • On Windows in addition to this recipe in order to stop appearing of files "*.un~" you should in the file $VIMRUNTIME/vimrc_example.vim comment out three lines "if has('persistent_undo') set undofile endif". Then there is backup of files in the temporary folder. – Andrew Krizhanovsky May 18 '18 at 09:30
22

It sounds like you're looking for the nobackup option:

:set nobackup

Backups are not turned on by default, so you've probably got a config file somewhere that's turned them on.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
3

On windows, I had set nobackup in C:\Users\my-user-name\_vimrc file; but that didn't seem to work. I then added set nobackup to C:\Program Files (x86)\Vim\_vimrc file. Still didn't work!

I later figured that C:\Program Files (x86)\Vim\_vimrc loads a sample vimrc script from $VIMRUNTIME/vimrc_example.vim and that script has this snippet:

if has("vms")
  set nobackup      " do not keep a backup file, use versions instead
else
  set backup        " keep a backup file (restore to previous version)
  if has('persistent_undo')
    set undofile    " keep an undo file (undo changes after closing)
  endif
endif

Commenting that out worked for me! So it really comes down to figuring out the order in which these scripts are getting executed, thereby overriding anything you might have done.

Raghu
  • 1,415
  • 13
  • 18
1

Two files will be created after editing. A file with "~" suffix, and another one with "un~". Add the lines below in the _vimrc or .vimrc file:

set nobackup
set noundofile
0x00A5
  • 1,462
  • 1
  • 16
  • 20