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 [email protected]
then from there log into the secure server like so:
ssh [email protected]
I have keyless ssh set up, so I can automate the process like so:
ssh [email protected] -t "ssh [email protected]"
is there anyway to remotely edit a file such as secure.university.com/user/foo.txt
on my local machine?
EDIT:
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://[email protected] scp://[email protected]//home/user/foo.txt
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 [email protected] 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With