Edit files remotely

4.2
(196)

We recently wrote about using netrw for file system exploration in Vim. Netrw is a versatile plugin that has been included standard with Vim since version 6.0 — you probably already have it! One of its many features allows editing files on remote servers via scp and several other protocols. You can open a file directly from the command line like so:

vim scp://foo.example.com//path/to/file

If you’re in Vim already, read the file into a buffer with e, for edit:

:e scp://foo.example.com//path/to/file

Of course, you can also use :split, :vsplit, or :tabedit inside Vim to open in a horizontal split, vertical split, or tab, respectively.

When specifying the file path, use either a relative path, relative to your home directory on the remote machine, or use an absolutely path by prepending your path with a /, making a double // after your hostname.

Opening a remote file like this will actually download the file to a temp directory. When you write your file with :w or :wq in Vim, the temp file is uploaded to the the remote host. That’s really all there is to it! Watch the gif for a demonstration:

How useful was this tip?

Average rating 4.2 / 5. Vote count: 196

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts