3

I installed vim on windows 10 using chocolatey. When I edit a foo file in powershell, vim leaves behind .foo.un~ or .foo~ files. What are these and how do I stop vim from leaving them around?

Heath Borders
  • 1,210
  • 9
  • 11

1 Answers1

6

These files are backup and undo files. vim also creates swap files if it crashes while editing.

From https://coderwall.com/p/sdhfug/vim-swap-backup-and-undo-files

In powershell, create the following directories:

~/.vim
~/.vim/.undo
~/.vim/.backup
~/.vim/.swp

Edit your .vimrc file by opening vim and typing:

:edit $MYVIMRC

Then, add the following lines, and save:

set undodir=~/.vim/.undo//
set backupdir=~/.vim/.backup//
set directory=~/.vim/.swp//

vim will now put your undo, backup, and swap files in the ~/.vim/.undo, ~/.vim/.backup, and ~/.vim/.swp directories, respectively.

Heath Borders
  • 1,210
  • 9
  • 11
  • 1
    editing $MYVIMRC for me opens `C:\Program Files (x86)\Vim\_vimrc` which does not have user permission to write (i.e. readonly , and force-write fails with permission error) (although I didn't install via chocolatey as OP did) – M.M Jan 14 '21 at 02:18
  • 1
    Why is the double forward slash at the end of the path necessary? *EDIT* From a comment in the link: "the "//" at the end of each directory means that file names will be built from the complete path to the file with all path separators substituted to percent "%" sign. This will ensure file name uniqueness in the preserve directory." – mdozer Apr 29 '21 at 17:57