When I create .txt files using Vim the following files are also created. How do I prevent/remove/auto-delete the files ending in ~?
1 Answer
The files you see are the backup file quotes.txt~ and the undo file .quotes.txt.un~.
Turn them off
You can prevent these files from being created by adding the following lines to your vimrc:
set nobackup set noundofile The backup file will still be created when writing a file but should not stay around. You could set nowritebackup to disable this as well although I would just leave it on.
See :help backup-table to find out which options work best for you.
Without an undofile, you will lose the ability to undo changes after closing and reopening a file. See :help undo-persistence for more information.
Put them somewhere else
You can specify another directory for the backup and undo files by setting the backupdir and undodir options. The best way, IMHO, is to create a directory in your $HOME. It will persist across reboots and only be accessible to you. For example:
set backupdir=$HOME/.vim/tmp/backup/,/tmp,. set undodir=$HOME/.vim/tmp/undo/,/tmp,. The example above will still use /tmp and the local directory as fallbacks.
Ignore them
If you're working with a VCS, you may want to just add the patterns to ignore them to your user configuration.
- 1I created the backupdir & undodir directories. That solved the issue. I also learned something about using the .vimrc file, using :help, and about creating a .gitignore file. Thanks so much!javilan– javilan2024-04-05 21:23:56 +00:00Commented Apr 5, 2024 at 21:23

:help 'backupdir'and:help 'undodir'to put them somewhere else.