Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparently edit remote files on Windows, with ssh/Putty and netrw

Tags:

vim

Ok guys, maybe this one has been asked before, but I searched and ran threw nothing, so i'm taking a chance here.

I'm using the latest vim (gvim 7.3), on Windows 7 64bits.

I've got some remote files that I want to edit directly with vim, using netrw.

Right now, I've got a fully working transparent ssh connexion to my remote hosts, thanks to Putty, Pageant and public/private keys.

I've successfully setup a read/write access to distant files with those 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 a file with :

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

And, each time I access remote file, Vim run a windows prompt (cmd.exe) :

C:\Windows\system32\cmd.exe /c c:\"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 hitting a key outside Vim each time I want to open/write a file isn't efficient at all.

So my question(s) is(are) :

  • Am I doing it the right way ?
  • Is there another way of transparently accessing a remote file with ssh on Windows ?
  • If no, is there a way to get rid of "Hit any key to close this window..." when Vim launches putty's pscp.exe ?

Thanks a lot and happy vimming.

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

like image 719
bPizzi Avatar asked Aug 23 '10 10:08

bPizzi


1 Answers

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

set nocompatible
let g:netrw_cygwin = 0
let g:netrw_list_cmd = "plink.exe -P ##### -pw MyPass [email protected] 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 [email protected]"

With the first command make sure there's a [space] after -Fa or you'll get errors. Then you can connect in Vim via

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

I hope this helps some Vimmers struggling to figure this out and get it working. Cheers!

like image 163
James Affleck Avatar answered Oct 14 '22 23:10

James Affleck