3

By default, vim seems to save a backup file ending in a tilde (see :help backup). For example, when editing foobar.txt, a backup file foobar.txt~ is saved. I would like to have it saved to .foobar.txt~ instead. On Linux, a file starting with a dot is considered a hidden file.

I can't use the option backupext because it only allows use to set an extension and not a prefix.

1
  • 3
    Consider using backupdir to keep your backups away from your source?
    – D. Ben Knoble
    Commented Jan 10, 2019 at 14:11

1 Answer 1

1

I'd recommend to keep all of Vim's backup and state files in their own directory:

set directory=$HOME/tmp/vim//
set backupdir=$HOME/tmp/vim//
set undodir=$HOME/tmp/vim//

The two slashes at the end are important to ensure names are unique:

For Unix and Win32, if a directory ends in two path separators, the swap file name will be built from the complete path to the file with all path separators substituted to percent '%' signs. This will ensure file name uniqueness in the preserve directory. (:help directory)

It is possible to store these file in the current directory as well -- see the documentation :help directory.

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.