One of the lesser known features of Vim is the ability to edit files remotely, over the network.
This feature comes with the netrw plugin. To achieve this, netrw uses the SSH protocol, and manages remote files via the
Here’s how to do it:
Note the double
/ for the directory on the remote host, which is needed to correctly resolve the absolute path.
[:port] is optional.
So with the command above you can open a file located on a remote host for editing.
What actually happens in the background is that Vim uses
scp to download the requested file from a remote machine to a local
/tmp directory, and then opens it for editing.
When you save your changes to the file, the changes are first applied to a local copy in
/tmp directory. After that, the file is uploaded via
scp to the remote host.
If you open a directory on a remote host, you could also use netrw to browse through remote files and directories. The important thing is to always specify the directory path with
/ at the end.
Of course, it’s recommended that you use SSH keys for authentication. Otherwise, you might be asked for the SSH password too often.
Beside SSH, there are other protocols supported such as sftp, ftp, dav, etc.
For example, to open a file on a remote FTP server, you could run a command like:
Netrw offers lots of options and possibilities for remote editing, so for more information on this, take a look at
What you've just read is an a section of CHAPTER 6. WORKING WITH FILES from the book Mastering Vim Quickly.