Take the 2-minute tour ×

Although I have never tried this, it is apparently possible to remotely edit a file in vim as described here. In my particular case the server I need access to can only be accessed from on campus, hence I have to log into my university account like so:

ssh user@login.university.com

then from there log into the secure server like so:

ssh user@secure.university.com

I have keyless ssh set up, so I can automate the process like so:

ssh user@login.university.com -t "ssh user@secure.university.com"

is there anyway to remotely edit a file such as secure.university.com/user/foo.txt on my local machine?


My intention is to use vim on my local machine as it is impractical (move .vim folder, copy .vimrc) and in some cases impossible (recompile vim with certain settings, patch vim source, install language beautifiers) to make vim on the remote machine behave the way I want it to behave. What I want is to issue something like this (this is not accurate scp, I know)

vim scp://user@login.university.com scp://user@secure.university.com//home/user/foo.txt
share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

OK after a little working around I figured it out. First you have to edit (or create) your .ssh/config file as described here. For our purposes, we will add a line like this, which essentially adds a proxy.

Host secure
  User          Julius
  HostName      secure.university.com
  ProxyCommand  ssh Tiberius@login.university.com nc %h %p 2> /dev/null

Then we can simply copy (via scp) the file secure.university.com:/home/Julius/fee/fie/fo/fum.txt to the local computer like so

scp secure:/home/Julius/fee/fie/fo/fum.txt fum.txt

Extending on this, we can load it into vim remotely like so:

vim scp://secure//home/Julius/fee/fie/fo/fum.txt

or using badd like so:

:badd scp://secure//home/Julius/fee/fie/fo/fum.txt

To simplify my life, I added this shortcut to my .vimrc file for the most commonly used subfolder:

nnoremap <leader>scp :badd scp://secure//home/Julius/fee/fie/fo/fum.txt

So far vim has proven to be pretty aware that this is a remote file, so if the C file includes a file like so:

#include "foo.h"

it won't complain that "foo.h" is missing

share|improve this answer
add comment

Once you SSHed in the machine you can run any command(also vim) in remote host on your shell. After logging run vim as you are running in your machine.

share|improve this answer
sorry for the confusion, please see the edit I made –  puk Sep 18 '12 at 4:33
add comment

Since you are using ssh, you basically have access to the server via the CLI, as if you were sitting in front of the machine itself. With that said, you can use any program on that machine, just like you would use it on your own machine. Assuming that the secure.university.com/user/foo.txt means that there is a text file called foo.txt at location /user on the secure server, then the following commands would work after logging in through ssh:

cd /user
vim foo.txt

You could also use nano or any other CLI based editor that is installed on the machine.

share|improve this answer
I'm sorry, I must not have made it clear enough that I would like to remotely edit in vim. I will update my question to reflect this –  puk Sep 18 '12 at 4:26
add comment

Your Answer


