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?

1 Answer 1


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:


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.

  • 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, 2021 at 2: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, 2021 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.