原出處為: http://techrepublic.com.com/5100-1035_11-6028859.html?tag=nl.e011

Often, the life of a sysadmin consists of editing little configuration files here and there, and often on a remote system. Typically, a sysadmin will remotely log into the system, navigate to the file, edit and save it, then log out. A much simpler and quicker method of accomplishing the same task can be done with vim, without logging into and out of the remote system, provided you have SSH access.

For instance, to edit the file /home/joe/somesite.com/html/index.php, you could use:


$ vim scp://joe@host//home/joe/somesite.com/html/index.php


This will use scp to download the file, fire up vim locally to edit it, and upon saving the file, scp it back to the remote host. The basic syntax of the command is:

$ vim scp://user@host/[path_to_file]

Note the forward slash (/) delimiter between the hostname and the file name. Once you fill in the path, it will be preceded by a double forward-slash. If the file is in your home directory, this can be shortened to:

$ vim scp://joe@host/~/somesite.com/html/index.php

If you use this often, a simple wrapper shell script will ease the typing:

#!/bin/shvim scp://joe@host/$1

If you use this script, be sure to enclose the filename in quotes if you use the tilde (~) character to represent home directory; otherwise, your shell will expand it and pass it on to the script already expanded, which could cause havoc if your home directory on the local machine is /Users/joe but is /home/joe on the remote system. Place the shell script somewhere in your path, perhaps as ~/bin/vimhost and then execute it as:

$ vimhost "~/somesite.com/html/index.php"