Vim has a feature to edit remote files locally using network protocols such as scp, rsync, sftp, ftp etc.
This feature is provided by netrw plugin which is included as a standard plugin from vim versions 6+.
Files can be remotely edited using below syntax,
vim [protocol]://[user]@<hostname>[:port]/<path>
#or from directly inside vim as below
:e [protocol]://[user]@<hostname>/<path>
File path can be specified using absolute or relative paths as shown in below example,
#using absolute path and as a different login user
vim scp://myuser1@server9//etc/hosts
#using relative path
vim scp://server9/.ssh/config
If file path or exact file name is not known then the directory can be specified with a slash at the end to display the files and directories inside the given directory. Correct file can then be opened directly from the displayed list by choosing it and using enter key.
#provides directory listing of files inside ~myuser/docs/ directory
vim scp://myuser1@server9/docs/
Note:
- File opening and save will be slow due to the network latency and once the file is opened editing will be fast as the file is copied to local system before editing.
- This latency can be removed by setting ssh connection multiplexing as shown in Make SSH Connections Faster by Reusing an Existing Connection
References: