views:

435

answers:

5

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?

+2  A: 

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).

rampion
+1  A: 

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.

RandomNickName42
The netrw extension uses scp internally. I've had mixed luck with sshfs.
sirlancelot
Can you post your current config's? Also, check out http://vimdoc.sourceforge.net/htmldoc/options.html#'secure' , you may want to un-secure any of the sandbox options too, atleast until you get your backup working.
RandomNickName42
+1  A: 

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).

A: 

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

too much php
A: 

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 ?

Andrew Y