Skip to main content
added 21 characters in body
Source Link
Martin Tournoij
  • 63.3k
  • 26
  • 199
  • 274

In my vimrc I have:

set backupdir=~/.cache/vim/backup |call mkdir(&backupdir, 'p', 0o700)
set undodir=~/.cache/vim/undo     |call mkdir(&undodir,   'p', 0o700)

This stores a backup file in ~/.cache/vim/backup on every write, which is useful sometimes if I accidentally remove something, or remove something that I ended up wanting to have later anyway.

The problem is that the filename is just the "basename", that is, both ~/one/README.md and ~/two/README.md get written as ~/.cache/vim/backup/README.md, overwriting any previous file.

This problem doesn't exist for undodir, which stores it as two files, with the full pathname:

~/.vim/cache/undo/%home%martin%one%README.md
~/.vim/cache/undo/%home%martin%two%README.md

How can I keep a unique copy for every pathname, similar to what undodir does by default?

In my vimrc I have:

set backupdir=~/.cache/vim/backup |call mkdir(&backupdir, 'p', 0o700)
set undodir=~/.cache/vim/undo     |call mkdir(&undodir,   'p', 0o700)

This stores a backup file in ~/.cache/vim/backup on every write, which is useful sometimes if I accidentally remove something, or remove something that I ended up wanting to have later anyway.

The problem is that the filename is just the "basename", that is, both ~/one/README.md and ~/two/README.md get written as ~/.cache/vim/backup/README.md.

This problem doesn't exist for undodir, which stores it as two files, with the full pathname:

~/.vim/cache/undo/%home%martin%one%README.md
~/.vim/cache/undo/%home%martin%two%README.md

How can I keep a unique copy for every pathname, similar to what undodir does by default?

In my vimrc I have:

set backupdir=~/.cache/vim/backup |call mkdir(&backupdir, 'p', 0o700)
set undodir=~/.cache/vim/undo     |call mkdir(&undodir,   'p', 0o700)

This stores a backup file in ~/.cache/vim/backup on every write, which is useful if I accidentally remove something, or remove something that I ended up wanting to have later anyway.

The problem is that the filename is just the "basename", that is, both ~/one/README.md and ~/two/README.md get written as ~/.cache/vim/backup/README.md, overwriting any previous file.

This problem doesn't exist for undodir, which stores it as two files, with the full pathname:

~/.vim/cache/undo/%home%martin%one%README.md
~/.vim/cache/undo/%home%martin%two%README.md

How can I keep a unique copy for every pathname, similar to what undodir does by default?

Became Hot Network Question
added 8 characters in body
Source Link
Maxim Kim
  • 13.9k
  • 2
  • 20
  • 48

In my vimrc I have:

set backupdir=~/.cache/vim/backup |call mkdir(&backupdir, 'p', 0o700)
set undodir=~/.cache/vim/undo     |call mkdir(&undodir,   'p', 0o700)

This stores a backup file in ~/.cache/vim/backup~/.cache/vim/backup on every write, which is useful sometimes if I accidentally remove something, or remove something that I ended up wanting to have later anyway.

The problem is that the filename is just the "basename", that is, both ~/one/README.md~/one/README.md and ~/two/README.md~/two/README.md get written as ~/.cache/vim/backup/README.md~/.cache/vim/backup/README.md.

This problem doesn't exist for undodir, which stores it as two files, with the full pathname:

~/.vim/cache/undo/%home%martin%one%README.md
~/.vim/cache/undo/%home%martin%two%README.md

How can I keep a unique copy for every pathname, similar to what undodir does by default?

In my vimrc I have:

set backupdir=~/.cache/vim/backup |call mkdir(&backupdir, 'p', 0o700)
set undodir=~/.cache/vim/undo     |call mkdir(&undodir,   'p', 0o700)

This stores a backup file in ~/.cache/vim/backup on every write, which is useful sometimes if I accidentally remove something, or remove something that I ended up wanting to have later anyway.

The problem is that the filename is just the "basename", that is, both ~/one/README.md and ~/two/README.md get written as ~/.cache/vim/backup/README.md.

This problem doesn't exist for undodir, which stores it as two files, with the full pathname:

~/.vim/cache/undo/%home%martin%one%README.md
~/.vim/cache/undo/%home%martin%two%README.md

How can I keep a unique copy for every pathname, similar to what undodir does by default?

In my vimrc I have:

set backupdir=~/.cache/vim/backup |call mkdir(&backupdir, 'p', 0o700)
set undodir=~/.cache/vim/undo     |call mkdir(&undodir,   'p', 0o700)

This stores a backup file in ~/.cache/vim/backup on every write, which is useful sometimes if I accidentally remove something, or remove something that I ended up wanting to have later anyway.

The problem is that the filename is just the "basename", that is, both ~/one/README.md and ~/two/README.md get written as ~/.cache/vim/backup/README.md.

This problem doesn't exist for undodir, which stores it as two files, with the full pathname:

~/.vim/cache/undo/%home%martin%one%README.md
~/.vim/cache/undo/%home%martin%two%README.md

How can I keep a unique copy for every pathname, similar to what undodir does by default?

Source Link
Martin Tournoij
  • 63.3k
  • 26
  • 199
  • 274

How can I prevent files in backupdir from overriding similar named files?

In my vimrc I have:

set backupdir=~/.cache/vim/backup |call mkdir(&backupdir, 'p', 0o700)
set undodir=~/.cache/vim/undo     |call mkdir(&undodir,   'p', 0o700)

This stores a backup file in ~/.cache/vim/backup on every write, which is useful sometimes if I accidentally remove something, or remove something that I ended up wanting to have later anyway.

The problem is that the filename is just the "basename", that is, both ~/one/README.md and ~/two/README.md get written as ~/.cache/vim/backup/README.md.

This problem doesn't exist for undodir, which stores it as two files, with the full pathname:

~/.vim/cache/undo/%home%martin%one%README.md
~/.vim/cache/undo/%home%martin%two%README.md

How can I keep a unique copy for every pathname, similar to what undodir does by default?