Update 2024-02: I wouldn’t bother doing any of this, I’d just use vscode-remote in VS Code. Easy!


Vim and Neovim come with the netrw plugin for editing remote files. The way I use this is to write a list of frequently used files in my scratch file for a project, and go to edit the file by putting the cursor over the line and hitting gf:

scp://carlo@192.168.1.9//home/carlo/foo-from-pscp.txt

I also have a Vim leader command to quickly open my scratch file:

map <Leader>0 :e /home/carlo/0.txt<CR>

Editing remote files is straightforward on Linux but on Windows 7 one has to use PuTTY’s pscp. In an enterprise environment there seem to be group policy settings that interfere with the default shell (or maybe my Cygwin environment does something - I can’t work out what the difference is).

First set up PuTTY, then set Vim’s _vimrc or Neovim’s init.vim.

PuTTY Session Link to heading

Create a new Session. I called mine server:

Set the username to login with:

Set the private key (use PuTTYGen to create your key):

Test pscp in a command shell. Use -load server to load the Session.

C:\Users\carlo>pscp -load server foo.txt carlo@192.168.1.9:/home/carlo/foo-from-pscp.txt
foo.txt                   | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%

Vim 8.2 configuration Link to heading

On Windows the vimrc file is in a path like C:\Users\<user>\_vimrc.

" This file is C:\Users\carlo\_vimrc

syntax on
set incsearch

let g:netrw_cygwin = 0
let g:netrw_scp_cmd = "\"C:\\Program Files\\PuTTY\\pscp.exe\" -load server"

" I want to edit this remote file using 'gf'
" scp://carlo@192.168.1.9//home/carlo/foo-from-pscp.txt

Neovim 0.4.3 configuration Link to heading

Neovim’s equivalent of vimrc is a file like C:\Users\<user>\AppData\Local\nvim\init.vim

" This file is C:\Users\carlo\AppData\Local\nvim\init.vim

syntax on

set incsearch

let g:netrw_cygwin = 0
let g:netrw_scp_cmd = "\"C:\\Program Files\\PuTTY\\pscp.exe\" -load server"

" I want to edit this remote file using 'gf'
" scp://carlo@192.168.1.9//home/carlo/foo-from-pscp.txt

Neovim 0.4.3 configuration on an enterprise system Link to heading

The same version of Neovim on an old Windows 7 work laptop failed to edit remote files. It kept complaining about not being able to start /bin/bash. To get it to work there I had to force the shell to cmd.exe and use a slightly different scp command. No idea why.

let shell=cmd.exe
let g:netrw_cygwin = 0
let g:netrw_scp_cmd = 'C:\"Program Files"\PuTTY\pscp.exe -batch -q -i C:\work\ssh\ssh-putty-laptop.ppk -scp'

Further reading Link to heading