I do most of my work in vim. I much prefer to edit files using vim locally rather than sshing into a server and running vim there, for many reasons, one of the most important being UI responsiveness on a slow connection.
I know that I can edit remote files using vim and scp and I also have a setup with sshfs that allows me to quite simply cd to a mount point and vim up some files.
However, it really bothers me that every time I save the file, it writes the whole file to the remote server. This really slows down my workflow.
What I really would like to do is have some sort of setup like this:
- When opening a remote file with local vim, pull the file's contents and a hash of the file
- When saving the file, check if the remote hash has not changed, and if it has not, upload a diff and patch the remote file with the new changes.
- Preferably do this all through a persistent ssh connection, so that no time is lost opening a new connection each time.
This would be much faster and much more bandwidth efficient, and have the same functionality.
I usually use git or svn to achieve a similar result, but I really want this kind of minimal functionality for situations when I do not have the luxury of using such SCM systems.
My questions are:
1. Does anyone know of any existing scripts or programs that will do some or all of this for me?
2. Anyone care to whip up some bash one liners that will do the trick? I know it should be able to be done with a few of these...
xdelta
could do the patching and the hash check for you.Here is a go, assuming you have the file mounted with sshfs. I kept the file extension in case you want to enjoy syntax highlighting:
Let's say you call it deltavim or something, you just
This will need two copies locally to make the delta, but removes all that if successful. It leaves the original remote file with a .orig, but you can add a line to delete that after the patch if you'd like.
If the remote file changes while you're editing, xdelta will notice that and refuse to patch.
Anyway, maybe that's a starting point for you.
Good luck! (...and never point a loaded, untested script you get off the internet at a file you love...)
When you remotely connect with
vim
, does it actually write the whole file?