Create local backup when editing remote files via netrw in vim
Asked Answered
C

5

6

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?

Cower answered 18/2, 2009 at 23:47 Comment(1)
Have you tried setting 'backupdir' to a local folder?Schick
H
2

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

Hippolytus answered 19/2, 2009 at 2:41 Comment(0)
S
2

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

Schuck answered 18/7, 2009 at 21:58 Comment(0)
P
1

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.

Proportionable answered 14/7, 2009 at 17:42 Comment(2)
The netrw extension uses scp internally. I've had mixed luck with sshfs.Cower
Can you post your current config's? Also, check out 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.Proportionable
S
0

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

Schick answered 20/7, 2009 at 8:40 Comment(0)
T
0

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 ?

Tumid answered 20/7, 2009 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.