Nav links

Friday, 22 September 2006

Remote editing with Vim

The old-fashioned way to edit remote files locally was through a continual process of:


  1. use FTP program to download file

  2. use local editor program to edit file

  3. use FTP program to upload file

  4. test changes, and repeat from step 1



This was then refined through the use of more advanced FTP software, such as Filezilla.


  1. use FTP program to choose file to edit

  2. local editor is automatically opened by FTP program to edit file

  3. when editor is exited, FTP program takes over to upload changes

  4. test changes, repeat from step 1



The problem with this approach is that you have to exit your editor to upload and test changes, then open it again for further work. Luckily, for those people who use Vim, there is now an easier method:


  • edit in Vim



That's right. You can just specify a remote file to load, and Vim takes care of everything. For example, to start editing a remote file via FTP from the command line:

gvim ftp://username@ftp.servername.net/folder/filename.php



Whenever you do a save, it'll be uploaded via FTP transparently.



This magic is performed by the netrw module, which you can find more about by typing :help pi_netrw.txt into Vim.



I did have to do a bit of fiddling to get this working on Windows (with Vim 7.0), though. As also found by a couple of people in the Vim mail archive, I received a file not found message whenever Vim tried to upload my changes. As suggested by the author of this Vim module, installing a new version of the module fixed the problem. To achieve this:


  • download Vimball. This is an automatic installer for Vim modules. The version included with Vim 7.0 doesn't seem to work on Windows, so we'll get a newer version.

  • install Vimball. The official instructions didn't work for me on Windows, as noted in the previous point, so it can't install itself. Instead, for step 2, I had to unpack the vimball.tar.gz file with a separate archiver, and copy the resultant files into their correct folders.

  • download netrw

  • install netrw, this time following the official instructions. If you have problems, try unpacking the netrw.vba.gz file first.