Neovim and Vim both come bundled with a standard plugin called Netrw. Netrw acts a file explorer (similar to NERDTree), but more importantly has the ability to work with scp (as well as sftp, rcp, ftp, and lots of others :h netrw-nread
) to let you edit files and browse directories that are hosted on a remote machine, inside of your local Vim instance.
This is useful since you are able to use your Vim setup and plugins without copying over your dotfiles to the remote machine. As well, since the file is copied to your local machine, there will be no delay when typing.
This is optional for Vim, but required for Neovim (check this Neovim issue explaining why).
Typically, each time you use scp, you must input your password. This can be tedious especially since this means each time you read or write a remote file/dir, Netrw will prompt you for your password.
You can avoid having to input your password for each scp and ssh session by following these instructions or by following these instructinos for OSX (~/.ssh/id_dsa.pub
should be ~/.ssh/id_rsa.pub
).
You can start Vim to edit a remote file with the following:
$ vim scp://[user@]machine//absolute/path/to/file.txt
or
$ vim scp://[user@]machine/relative/path/to/file.txt
Note: For an absolute path, you must have the double backslashes before the path.
Note: replace vim
with nvim
for Neovim
If you are inside Vim then you can read a remote file as follows:
:Nread scp://[user@]machine//absolute/path/to/file.txt
or
:Nread scp://[user@]machine/relative/path/to/file.txt
If you open a remote file with :Nread
then you can save your changes with :w
and the remote file will be written to.
If you want to create a file on your remote machine. You create it as you would normally, then write it using :Nwrite
as follows:
$ vim myfile.txt
:Nwrite scp://[user@]machine/relative/path/to/file.txt
Since Netrw doubles as file browser, you are also able to browse a remote directory in Vim. Use the same command above, but terminate the path to the directory with a /
(this is a must).
:Nread scp://[user@]machine//absolute/path/to/dir/
$ vim scp://[user@]machine//absolute/path/to/dir/
Open Vim and type the following:
:h netrw
Since you are copying the remote file, there will be a latency with most commands (But no latency when typing since you have a local buffer of the file). Browsing a directory, writing a file, read a file will all have a noticible amount of latency. All latency will be blocking so you will not be able to use Vim while the scp is being done.
scp
was used as follows:
$ vim scp://[user@]machine//absolute/path/to/file.txt
If your username was jsmith
and the remote machine was linux.student.cs.uwaterloo.ca
then the complete command would be:
$ vim scp://[email protected]//absolute/path/to/file.txt
"This is useful since you are able to use your Vim setup and plugins without copying over your dotfiles to the remote machine. As well, since the file is copied to your local machine, there will be no delay when typing."
Is this plugin just lie the remote-development extension in vscdoe?
I think setuping vim on the remote machine is better than using netrw.