I have a remote Linux machine which I use as a development server for a web application. I cannot reproduce the environment locally, the files must execute on the remote server, but I want to edit them locally (in vim).
The files on this remote server are managed via Git. I typically only edit between 1-5 files at a time out of several hundred.
Suggested solutions, and why they don't work well:
sshfs: This solution seems awesome, but there are some bugs.
- The local editor will hang while saving for a few seconds – there is no asyncronous saving in case of network delays.
- If the network goes down while sshfs is active, it will actually brick that part of the filesystem until you do some hacky things to unmount it: http://sourceforge.net/p/fuse/mailman/message/26936619/
- Overall quite slow since it constantly syncs data, rather than creating a local copy of that one file while editing
gvfs:
- Operation is slow – takes a long time to open files, and the directory tree is not cached. Additionally, there is a bug (over 5 years old) which causes vim to trample over file permissions, meaning I have to update permissions via a remote ssh constantly
rsync:
- Since this is a git repo, I may need to change branches frequently. There are times when the remote server may need to update me, and vice versa. Overall this adds a lot of complexity and would require manual syncing whenever I want to check a change on the remote server.
Use vim on remote machine via terminal:
- There is a keystroke delay – this drives me insane.
gftp
- The temporary file it creates has an arbitrary name – so you can't tell what tab is what
- Requires a close of vim to update remote server (inane)
Surely there must be a better way? On Windows, I have used winSCP, which basically makes a temp copy of the file locally that you edit, and when you save it, it syncs the file in the background (so you can continue in the editor instantly after a save).
I found this question about emacs, but I don't want to use emacs 🙁
how to ssh to remote server and use local emacs to edit files?
Best Answer
One option missing from your list is Vim's netrw plugin (first mentioned by @godlygeek in the comments), which ships with Vim. You can
:edit scp://hostname/path/to/file
, or even specify such URL on launch:$ vim ftp://hostname/path/to/file
. It supports multiple protocols, and handles the download / upload transparently (on each:write
), while keeping the original filename, so filetype detection etc. still work.