VIM with SFTP/FTP on Mac and Windows

If you’re a developer there is a pretty good chance that you spend a lot of time in either Sublime Text or MacVim [gVim on Windows] wrangling code. MacVim is one of the most popular and modern incantations of the vim editor, which is itself an improved version of ancient vi editor initially developed by Bill Joy (also popularly  known as co-founder of Sun Microsystems) in 1976. You’re doing something right if your interaction paradigm hangs around for nearly 40 years.

Vim has a robust environment for plugins and a solid community of developers using and creating plugins to extend the functionality. There are a couple plugins out there to connect Vim to cloud storage, like vim-sync but as you can see [at least of the time of this writing], they are fairly spotty. Just hanging out in Github with a few commits and not much maintenance.

Connecting Vim to an SFTP server

Combining Vim and ExpanDrive is a powerful workflow – you actually edit and manipulate files on SFTP/FTP or S3 in real-time from directly within the editor. You don’t need to download the file, edit it, and then re-upload it. Here is a quick tutorial on how to get it going

Download ExpanDrive
First you want to download the latest ExpanDrive release here.  ExpanDrive is free to download and try out and is available on Mac and Windows. While these screenshots are on the Mac, it looks pretty much the same on Windows.

Create new SFTP Drive
Once you have installed ExpanDrive, you create a mapped drive to the remote server . This screenshot shows how you’d get going to setup MacVim with SFTP.

Select Authentication
Setup whatever SSH configuration options are needed for your connection, and then save the connection.. We generally use public key authentication combined with Google Authenticator for multi-factor authentication. You can even set a remote path so that you can mount /etc and twiddle configuration files directly. Once you’ve connected you’ll have a network drive accessible that you can easily use to browse the files on the SFTP server.

Server in Finder

Now you’re ready to start editing files via SFTP in Vim. A nice fork of Vim is the Alloy MacVim fork, which adds a sidebar to browse your project as well as a quick open, among other things. Vim purists will hate this, but I benefit from having a project structure visible.

Now you can edit any file directly within Vim and have the entire tree visible in the sidebar. Like I mentioned above, there are some other options out now for accessing SFTP servers from within Vim, I feel pretty confident that ExpanDrive is the best. We have rock-solid background saves that let quickly save . You’ll have no delay as the file is saved instantly and pushed out to your server in the background.