Create local backup when editing remote files via netrw in vim

I work with many files remotely using vim and the netrw plugin. I also save temporary backups by modifying &backupext (found in the documentation ).

While working in a remote file (scp: //server//folder/file.txt), I noticed that when it is saved, the backup copy is not even performed.

Is there any way that a backup is automatically created locally (according to vim backup settings) every time I save a deleted file?

+6
vim scp backup netrw
source share
5 answers

I do not think there is a simple setup for switching. You could try the script something though - add your own autocommand BufWriteCmd to write a backup. Try using set verbose=9 for debugging (and see how netrw works).

+2
source share

I once struggled with a variant of this problem: keeping local records of changes that I made in the same source tree on the same remote computer.

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

Solution 1: use Autocommand BufWritePost to call scp to copy the file after it is written. This can work quite efficiently if the system allows processes to exchange file descriptors, since you can start an ssh master session on a remote computer 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 discuss a new connection for each file can be painful.

Solution 2: for Windows, use WinSCP , which has the “save the remote machine” mode, in which it controls the directory and all its subdirectories for changes, and then automatically distributes the changes, given the set of rules (patterns for ignoring, transfer mode for different types of files and etc.).

+2
source share

Well, judging by the use of your scp protocol, it seems that it would be much easier for you to use fuse sshfs , which will allow you to have normal file system behavior that supports you, and not just the CRUD interface for push / pull.

+1
source share

The netrw plugin completely bypasses the command :write , the only way to return the functionality of the “backup” is to do it yourself using autocommands.

0
source share

I understand that this is not a direct answer to the original question. However, what you do seems like a simple VCS-in-disguise - that’s the reason why you didn’t do deleted files, for example. a git, then clone this repository locally and push changes after editing?

0
source share

All Articles