1

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.

  • 3
    Consider using backupdir to keep your backups away from your source? – D. Ben Knoble Jan 10 at 14:11
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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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