Open multiple files in tabs remotely in gvim with nautilus

86me's picture

I have been looking for the easiest way to develop web applications on a remote machine. A stack of ssh sessions running vim is usually enough, but sometimes you need more.

I really enjoy being able to mount a file system in nautilus using SFTP. So then I'm all set, right? Just find the file I want to edit on the remote machine in nautilus and open it up in gvim. Not so fast. Files will not open in gvim over SFTP. They'll open in gedit, no luck for gvim though. After poking around a bit I decided a nautilus script was the way to go. Make a file in ~/.gnome2/nautilus-scripts and chmod it u+x. I named mine "gvim (sftp)"

#!/bin/sh
#This script opens the selected files remotely, in tabs, in gvim
URI=`echo $NAUTILUS_SCRIPT_SELECTED_URIS | sed -e s^home^/home^g`
gvim -n -p $URI

The sed command adds an extra forward slash before home to denote an absolute file path. The [-n] disables swap file usage so files don't get left all over the place when connections are interrupted. the [-p] is for tabs. Enjoy!