Vim backupcopy choice for retry-safe writes on network filesystems
0 reputation · 25 Nov 2020, 04:46 UTC
I need to configure Vim so that an interrupted write to a shared network filesystem leaves the original file intact, while also ensuring that hard links to that file remain valid after a successful save. The documented behavior indicates that writebackup creates a temporary backup before overwriting, and backupcopy determines whether Vim copies the original or renames it to a backup name. When backupcopy is set to auto, Vim may choose rename-based writes on some systems and copy-based writes on others, which introduces uncertainty about whether inode numbers and hard links survive.
The core tension is that rename-based writes avoid momentarily duplicating the full file contents, yet they replace the original inode and break existing hard links. Copy-based writes preserve links but temporarily duplicate data, and some network filesystems may not support the rename semantics atomically. Because behavior can differ across Vim versions and operating systems, I am unsure which documented setting gives a predictable, retry-safe result without silently changing link relationships.
Can Vim be configured to use a single backupcopy strategy that both survives interrupted writes and preserves hard links on filesystems where rename is not atomic? Which option value should be preferred when the priority is avoiding duplicate data rather than preserving inode identity? Does the automatic choice differ between regular files and symlinked targets in a way that can be relied upon across versions?