vim |scp |ssh

Remotely Edit Files in Vim

serhatteker

Serhat Teker

Posted on January 25, 2021

Remotely Edit Files in Vim

If you want to edit files on a remote server with your current lovely vim configs there are 2 options:

One is to copy your .vimrc to all servers. Which is not efficent and denying one of the main software development principle -DRY ,

Another one is instead of bringing .vimrcto each server you need to work on, edit the remote files from your local vim:

Start vim like this:

$ vim scp://remoteuser@host//path/to/file/file.extension
Enter fullscreen mode Exit fullscreen mode

If you have already a vim session:

:e scp://remoteuser@host//path/to/file/file.extension
Enter fullscreen mode Exit fullscreen mode
  • remoteuser is the user name on the remote server
  • host is the remote server name/ip

This opens the file seamingly in place (it actually copies the file locally), and when you save, it sends the edited file back to the server for you.

It asks for an ssh password, but this can be streamlined via ssh keys.

The only drawback of this method is that you don't get path/file competion as you would when working directly on the machine which is not a big deal beside advantages.

All done.


Changelog

  • 2020-11-06 : Change title and filename. Add scp tag.
💖 💪 🙅 🚩
serhatteker
Serhat Teker

Posted on January 25, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Remotely Edit Files in Vim
vim Remotely Edit Files in Vim

January 25, 2021