When I create .txt files using Vim the following files are also created. How do I prevent/remove/auto-delete the files ending in ~?

enter image description here

  • 1
    Welcome to Vi and Vim SE. Please prefer to share textual data as text, not as an image. As to your question, these files are useful. See :help 'backupdir'and :help 'undodir' to put them somewhere else.
    – Friedrich
    Apr 5 at 5:01
  • 2

1 Answer 1


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.

  • 1
    I 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
    Apr 5 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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