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
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.
-
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.MJan 14, 2021 at 2:18 -
1Why 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."– mdozerApr 29, 2021 at 17:57