Transparently edit deleted files on Windows using ssh / Putty and netrw

Well, guys, maybe this has already been asked before, but I searched and ran without throwing anything, so I’ll take a chance here.

I am using the latest vim (gvim 7.3) on Windows 7 64bits.

I have deleted files that I want to edit directly with vim using netrw.

Right now, I have a fully working transparent ssh connection for my remote hosts, thanks to the Putty, Pageant, and public / private keys.

I have successfully set read / write access to remote files with these fixes:

#### .vimrc #### let g:netrw_cygwin= 0 let g:netrw_scp_cmd = 'c:\"Program Files (x86)"\PuTTY\pscp.exe -q -batch' let g:netrw_sftp_cmd= '"c:\"Program Files (x86)"\PuTTY\psftp.exe' 

Then I can access the file with:

 :e scp:\\user@host:port\\home\me\some-file.txt 

And every time I access the remote file, Vim launches the Windows prompt (cmd.exe):

 C:\Windows\system32\cmd.exe /cc:\"Program Files (x86)"\PuTTY\pscp.exe -q -batch -P 22 "C:\Users\me\AppData\Local\Temp\VIF215E.tmp" "user@host:/home/me/some-file.txt" Hit any key to close this window... 

My problem is that pressing a key outside of Vim every time I want to open / write a file is inefficient at all.

So my question is (is):

  • Am I doing it right?
  • Is there any other way of transparency accessing a remote file using ssh on Windows?
  • If not, is there a way to get rid of "Hit any key to close this window ..." when Vim runs putty pscp.exe?

Thanks a lot and a happy smile.

EDIT: Note to me in the past: Dude, just go with linux and vanilla gvim / ssh. You will thank me later (and look at spf13-vim)

+7
vim
source share
6 answers

This is what I got today (gVim 7.3 in Win 7) (took many hours to finally get something working):

 set nocompatible let g:netrw_cygwin = 0 let g:netrw_list_cmd = "plink.exe -P ##### -pw MyPass user@host.com ls -Fa " let g:netrw_ssh_cmd = "plink -T -ssh" let g:netrw_scp_cmd = "pscp -P ##### -pw MyPass -scp" let g:netrw_sftp_cmd = "pscp -pw MyPass -sftp" or let g:netrw_sftp_cmd = "psftp -P ##### -pw MyPass user@host.com" 

At the first command, make sure that [space] after -Fa, or you get errors. Then you can connect to Vim via

 :e scp://user@host:port#/(path to file) :e sftp://user@host:port#/(path to file) 

Hope this helps some Vimmers struggle to figure this out and make it work. Hooray!

+3
source share

It seems too complicated.

I use SSHFS for Linux to accomplish this. It allows you to locally mount a remote path through SSH.

Something similar is available for Windows now: http://dokan-dev.net/en/ . This should eliminate the need for all modifications on the Vim side.

+2
source share

Just put this line in your vimrc:

 let g:netrw_silent = 1 

This will cause scp to start asynchronously (e.g. using! Start)

+2
source share

Instead

 let g:netrw_scp_cmd = 'c:\"Program Files (x86)"\PuTTY\pscp.exe -q -batch' 

I had to use

 let g:netrw_scp_cmd = 'c:\"Program Files (x86)"\PuTTY\pscp.exe -q' 

On Windows 7, putty version 0.6, the -batch option does not work!

+2
source share

WINSCP is awesome. I think it copies the temporary file locally and then FTP, but it is transparent and very user friendly.

+1
source share

It is much easier for me to run cygwin. Install openssh and gvim in cygwin, then run:

 $ gvim scp://user@host//path/to/file 

Note the double slashes between the host and the loop. Without an additional slash, it will read the path relative to the user's home directory.

0
source share

All Articles