Question

I work with many files remotely using vim and the netrw plugin. I also keep timestamped backups by changing the &backupext (found in the documentation).

While working in a remote file (scp://server//folder/file.txt), I noticed that when I save it, a backup isn't even being made.

Is there a way I can have a backup automatically made locally (according to vim backup settings) every time I save a remote file?

Was it helpful?

Solution

I don't think there's a simple setting to toggle. You could try to script something though - add your own BufWriteCmd autocommand to write a backup. Try using set verbose=9 for debugging (and to see how netrw does it).

OTHER TIPS

I once struggled with a variant of this problem: keeping local records of changes I made to a single source tree on a single remote machine.

I maintained a local copy of the entire source tree and a local svn repository to version the files. Instead of using netrw and looking for a way to save backups locally, I edited everything locally and needed a way to automatically propagate my changes to the remote machine.

solution 1: use a BufWritePost Autocommand to invoke scp to copy the file after it's been written. This can work efficiently enough if the system allows processes to share file descriptors, since it's possible to run a master ssh session to the remote machine and share the connection for subsequent sessions. If you are less fortunate (I was working on a windows machine at the time), the time it takes to negotiate a new connection for each file can be painful

solution 2: for windows, use WinSCP, which has a "keep remote machine updated" mode, in which it monitors a directory and all its subdirectories for changes and then automatically propagates the changes, given a set of rules (patterns to ignore, transfer mode for different filetypes, etc).

Well judging from your scp protocol use, it seems that it would be a lot easier for you to be using the fuse sshfs, which would enable you to have normal filesystem behaviour backing you instead of just a push/pull type CRUD interface.

The netrw plugin completely bypasses the :write command, the only way to get the 'backup' functionality back is to do it yourself using autocommands.

I realise it's not a direct answer to the original question - however, what you are doing seems a lot like a simple-VCS-in-disguise - so is there a reason why you would not make the remote files e.g. a git repository, then clone that repository locally and push the changes after the editing ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top