This was discussed originally back in November of 2021
In that discussion there was a statement made that perhaps rclone's mount logic could watch for vim's file behavior if it was known what vim does.
It was also suggested to "disable the swapfile" in vim, however that isn't a valid workaround. If swapfile is set, then the active buffer is written periodically to a swap file. If it is not set then the active buffer is only in ram. This, however, has no effect on the mv, write, delete
operation that happens whenever a user uses :w
or :save
Today I was frustrated by this exact issue and found a relevant vim-specific stack overflow post. Over there, the original questioner showed how they used ionotify to see what vim was doing during file save.
The work around is to set backupcopy=yes
. Why this works is explained on :help backupcopy
in vim. Mine was set to auto
, which is the same as no
it seems. Basically with set backupcopy=yes
then vim makes a copy of the original file, edits the original file, and then deletes the backupcopy if all was successful. (If swapfile is set, changes are written to the swapfile, the backup is made, the swapfile is moved over the original file, and then the backup is deleted).
The "broken" behavior is if backupcopy=no
, then the original file is renamed, a new file is written with the original file name, and then the original (now renamed) file is deleted. This seems to happen fast enough that rclone doesn't seem to notice the rename, as the file that shows up in my trash has the original file name.
It would be great if rclone worked with vim's default settings, as setting backupcopy=yes
does slow down file io a bit. But this also seems like something that would be a bit brittle to detect.