Short Question: This is failing. Is it valid syntax?

:tabedit scp://[home]/~/stuff/01234567/update/notes.txt

Alternatively, can I easily use a longish somewhat complex shell command in vim to get environment info and use that output in place of the [home] notation?

Long Question: I'm trying to use Netrw within vim to edit a file on my home machine. I am ssh'ed over VPN to the remote machine and then the connection from the remote machine is coming back through the VPN connection to my home machine.

This is what I'm trying to get working in vim:

:tabedit scp://[home]/~/stuff/01234567/update/notes.txt

A tab opens and I see this at the top: s//[/~/s/0/u/notes.txt

The [ is wrong and the opened file is not the file from the home machine. The file exists on my home machine and I have text in the notes.txt file. When the command works(see below) I can see the text and edit the file.

When I explicitly pass the username and IP address it works:

:tabedit scp://user1@

and the tab looks like this: s//u/~/s/0/u/notes.txt

Note the first u where the failing has a [.

Since the IP address for the VPN connection back to my home machine is dynamic and .ssh/config cannot use variables, I'm using a ProxyCommand to find it and connect. In order to make the ProxyCommand specific to this host/connection, I'm using a Host keyword in .ssh/config. I believe the ProxyCommand is working to find the IP address because I am prompted to enter my password. Like: user1@'s password:

Host home 
 HostName home
 User user1
 IdentityFile ~/.ssh/user1.key
 ProxyCommand ssh -ttvvv  $(env | grep 'SSH_CONNECTION' | awk 'match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/){print substr($0,RSTART,RLENGTH)}' )   

The username from the Host stanza is not working and if you look at the tab path you can see the failing has an [ where it should be the first letter of the username. The username on the remote and local are the same. On the failing, it does have my username at the password prompt so it must be picking it up from the environment.

Similarly, my identity file is not working since I'm prompted for the password, but I can use keychain to bypass the need to input my password. I believe the [home] part of the scp://[home] is working because if I use

:tabedit scp://[blah]/~/stuff/01234567/update/notes.txt I am not prompted for the password but the opened tab is not the remote file either.

The last few lines of debug output:

debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
debug3: send packet: type 1
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i0/0 o0/0 fd 4/7 cc -1)

debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
"/tmp/vWJoocD/0.txt" [New File]

I've tried many combinations of this:

:tabedit scp://[home]/~/stuff/01234567/update/notes.txt

:tabedit scp://[user1@][home]/~/stuff/01234567/update/notes.txt

:tabedit scp://\[home\]/~/stuff/01234567/update/notes.txt

:tabedit scp://'[home]'/~/stuff/01234567/update/notes.txt

and modifying the .ssh/config file but have not had success.

I'm using this method to avoid copy-pasting from the remote system to my home because there are lots of copy/pastes throughout the day, each going to different files. I can use tmux much easier and faster than the mouse.

sshfs is not available on the remote.

I don't want to use a reverse tunnel as that requires a listening port on the remote.


  • remote machine: vim 7.4, RHEL 7.8
  • home machine vim 8.2, Fedora 33

Thank-you for reading and I appreciate any advice.

  • 2
    Can you ssh [home]? I would expect you to need to leave off the square-brackets, based on your .ssh/config. Then also leave them off for scp. – D. Ben Knoble Nov 29 '20 at 13:16
  • 1
    I don't think you need the brackets... If it's in your .ssh/config, then just home will work. Did you try to simply use scp://home/...? I'd expect that will work just fine... – filbranden Nov 29 '20 at 16:02
  • 1
    ssh host and ssh [host] fail. This is close: ` Host home User user1 IdentityFile ~/.ssh/user1.key Port 22 ProxyCommand ssh -ttvvv -oport=22 <not included> ` fails: ` Bad packet length 218783296. ssh_dispatch_run_fatal: Connection to UNKNOWN port 65535: message authentication code incorrect ` Works, :tabedit scp://home/~/stuff/01234567/update/notes.txt but defeats the purpose: ` Host home HostName User user1 IdentityFile ~/.ssh/user1.key Port 22 ` Thanks for the ideas. This is an ssh question and I'll move it to an ssh forum. – Gary Nov 29 '20 at 16:26

With enough searching and trial and error, this is what ended up working:

Host home 
 HostName * 
 User user1
 ControlMaster auto
 ControlPath ~/.ssh/master-socket/%r@%h:%p
 ControlPersist yes
 ProxyCommand nc -v  `env | grep 'SSH_CONNECTION' | awk 'match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/){print substr($0,RSTART,RLENGTH)}' ` "%p"

Vim command:

$ vim scp://home/~/stuff/01234567/update/notes.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.