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
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
Create a new Session. I called mine
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 firstname.lastname@example.org:/home/carlo/foo-from-pscp.txt foo.txt | 0 kB | 0.0 kB/s | ETA: 00:00:00 | 100%
Vim 8.2 configuration
On Windows the vimrc file is in a path like
" 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://email@example.com//home/carlo/foo-from-pscp.txt
Neovim 0.4.3 configuration
Neovim’s equivalent of vimrc is a file
" 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://firstname.lastname@example.org//home/carlo/foo-from-pscp.txt
Neovim 0.4.3 configuration on an enterprise system
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'