I've read that most editors will replace the file when you actually want to save changes to that file: How to execute a command whenever a file changes?
How does Vim behave?
I've read that most editors will replace the file when you actually want to save changes to that file: How to execute a command whenever a file changes?
How does Vim behave?
it might depend on various settings related to 'backup', everything that has to keep a copy of the file as it was before the write happened. one of settings that controls that is: 'backupcopy':
When writing a file and a backup is made, this option tells how it's done. This is a comma separated list of words.
The main values are:
"yes" make a copy of the file and overwrite the original one "no" rename the file and write a new one "auto" one of the previous, what works best
so, depending on your vimrc (backup
set and backupcopy
to no
), vim might rename a file. when
backup
... not a valid test :)
I've observed that the option writebackup
and whether the edited file has more than one hard link changes the behavior of Vim in that regard.
The following results pertain to Vim 9.0.2167 and Neovim 0.9.4 on Arch Linux using ext4 when saving a file with :w
.
writebackup
is on (which is the default)Editing a file with only one hard link to it:
Editing file with multiple hard links:
writebackup
is off (:set nowritebackup
)See also the backup
option:
If you write to an existing file (but do not append) while the 'backup', 'writebackup' or 'patchmode' option is on, a backup of the original file is made. The file is either copied or renamed (see 'backupcopy'). After the file has been successfully written and when the 'writebackup' option is on and the 'backup' option is off, the backup file is deleted. When the 'patchmode' option is on the backup file may be renamed.
'backup' 'writebackup' action off off no backup made off on backup current file, deleted afterwards (default) on off delete old backup, backup current file on on delete old backup, backup current file