Remote file comparison with Vim


I love Vim. It is my weapon of choice. One of the first things I always do when I install a fresh system is to install Vim and import my vimrc file. In this quick blog post I want to show you remote file comparison with Vim. As a server admin, I sometimes find myself having to compare two configuration files, one on my local system and the other on one of my servers. One option would be to down-/upload one file and vimdiff over here/there with the other file. No need for that. Vim let’s you compare remotely, by a simple combination of the vimdiff and scp commands.

In the screenshots below, you can see I’m comparing the buildout.cfg file of my local Plone instance and the one on a server (a server who’s hostname happens to be intranet).

$ vimdiff buildout.cfg scp://intranet//user/local/Plone/zinstance/buildout.cfg

The interesting part is the scp component. It might be a bit confusing at first, but it’s really easy to get used to: scp://hostname_OR_IPaddr//path/to/remotefile

All you really need to remember is the double slashes go before and after the hostname. The rest is an absolute path to the file being remotely compared.

You will be prompted for your password to the remote server. Type it and press Enter. You will get the following message:

Press ENTER or type command to continue

Usually, pressing ENTER is all I need for my purposes.

And voila, now you’re comparing two files, one is local and the other is stored remotely. To navigate between the two split windows, use Ctrl+w w. Of course you can edit both files freely and then save the changes. Local file gets saved locally and remote file stays on the server.


No Responses Yet to “Remote file comparison with Vim”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: