0

I realize "Why does Vim save files with a ~ extension?" was asked 10 years ago.

I tried using the following fix from that discussion, putting the following in my .vimrc file:

set nobackup       "no backup files
set nowritebackup  "only in case you don't want a backup file while editing
set noswapfile     "no swap files

But it doesn't work. I'm still getting littered with ~ files and want to stop these files from being generated. Is there a way?

I think part of the problem is that the lines above were followed by some boilerplate code in the .vimrc file that undid my commands:

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

I put my commands below this code and the backup files are no longer generated, but I'm still getting the undo files.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Argent
  • 885
  • 2
  • 9
  • 18
  • Don't put solutions in your question. SO isn't a message board, it's more like an online Q/A reference or a cookbook. As such, questions and answers are separate and have to be kept separate. See https://meta.stackoverflow.com/a/271399/128421 and https://meta.stackoverflow.com/q/267434/128421. Also, don't use "edited" or "updated" tags in the text. We can tell what's changed. Instead, incorporate the information into the question as if it'd been there originally, to maintain readability. – the Tin Man Dec 15 '19 at 21:09

2 Answers2

3

I know you said this isn’t what you want, but are you really sure?

Why do you not want backups or undofiles? The former is great for crash recovery, and the latter great for undoing things from many sessions ago. “I never need them” is probably wrong just because of “never.”

If you’re relying on git, go ahead. I love it. But it cannot recover things it never knew about, like code that you wrote in the middle of a session that crashed.

Why are you averse to these files? It is stupendously simple to keep undo files in their own isolated directory, and stupendously simple again to tell git to ignore all swap files. I’ll show you, for kicks:

For the undo directory, I have these 4 (yes, a mere 4) lines in my vimrc:

set undofile undodir=~/.undo
if !isdirectory(expand(&undodir))
  call mkdir(expand(&undodir), "p")
endif

For git, just this in your global gitignore will do:

*.*~
*.sw*

You can configure that file with core.excludesfile.

If you’re worried about disk-space, well, get a bigger disk. It’s not prohibitively expensive, and these files are tiny anyway, so I’m not sure that’s your real issue.

D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38
  • 1
    "_“I never need them” is probably wrong just because of “never.”_" Oh so true. But some people need to learn the hard way. – the Tin Man Dec 15 '19 at 21:17
0

Adding the following to the .vimrc file stops undo file generation:

set noundofile
the Tin Man
  • 158,662
  • 42
  • 215
  • 303