5

If I edit a directory (say 'foo') in Vim, then Vim always creates an empty directory named 'foo/~'. In my vimrc, I specify 'nobackup', 'nowritebackup', and 'backupdir=$TEMP/vim//'. With the backupdir setting, when I do enable backup files they go to the temp directory as expected.

Still, on both OS X and on Windows, Vim creates empty '~' directories, which are, of course, like leaving very dangerous mines littered around my machine (at least on OS X, where 'rm -rf ~' would be the start of a Bad Day).

I haven't been able to find any information about the empty '~' directory specifically, but lots on backups in general.

How can I disable the creation of empty '~' directories?

Steve Hollasch
  • 2,011
  • 1
  • 20
  • 18
  • Can you elaborate why you are editing a directory file? Ive just never done that. Usually if i need to change things i use terminal modifiers or cd into it to do child modifications. – Fallenreaper Apr 11 '16 at 19:32
  • @Fallenreaper best guess is that it's probably an accident most of the time. I don't think I've ever done it on purpose but it happens on nearly a daily basis – Ryan Haining Apr 11 '16 at 19:33
  • Vim allows you to browse directories directly by editing them. You can then navigate around a directory tree by moving to the line of the directory you want to view and hitting enter. It's a standard Vim feature. – Steve Hollasch Apr 11 '16 at 19:52
  • Note that this looks like it's related to netrw. For help, you can hit F1 in directory browse mode. If the help documentation let's me figure this out, I'll post back. – Steve Hollasch Apr 11 '16 at 19:55
  • 1
    I use the netrw file browser extensively. I haven't noticed that it creates an empty ~ dir, though. – Wayne Werner Apr 11 '16 at 20:18
  • I couldn't find anything in the netrw documentation to suggest an answer or resolution. Wayne's comment suggests that I might have some odd configuration that's doing this. – Steve Hollasch Apr 11 '16 at 20:25
  • Figured it out. See my answer below. – Steve Hollasch Apr 11 '16 at 21:37

1 Answers1

2

Figured it out. In my vimrc file, I had the following setting:

let netrw_home = "~"

I believe I originally did that to keep netrw from cluttering my home directory with ".netrwhist" and ".netrwbook". The problem is that the tilde wasn't expanded to my home directory, and instead netrw created a literal directory named "~" in the current directory to store those state files.

The fix I used was to leave the netrw_home variable undefined, and let it use the default value of the first directory on the 'runtimepath' path list. I had to add my home directory ($HOME) as the first directory on my runtime path, but so far that seems to work fine.

For whatever reason, I couldn't get ~ or $HOME to work for netrw_home on Windows, but that's probably my misunderstanding of some Vim details. I don't have time to investigate further, and I'm past this issue now, so that's where I'll stop.

Thanks to Wayne Werner above for doing a quick experiment to see if he had the same behavior. That's what kicked me in the right direction.

Steve Hollasch
  • 2,011
  • 1
  • 20
  • 18