Edit Remote Files Directly from Vim with netrw
This guide shows how to use Vim's built‑in netrw plugin to open, edit, and save files on remote Linux systems via scp, ftp, or other protocols, including command‑line examples, handling custom SSH ports, and using Nread/Nwrite within a Vim session.
What is netrw?
The netrw plugin, bundled with Vim since version 7.x, enables network‑oriented reading, writing, and browsing of files over protocols such as ftp, scp, rcp, and http. Run help netrw inside Vim for full documentation.
Opening a remote file with scp
To read or edit a file stored on a remote Linux host, use the following command: $ vim scp://[email protected]/info.txt This copies the remote file to /tmp, opens it locally for editing, and writes it back when you save.
Basic edit workflow
Inside Vim, press i to enter Insert mode, modify the file, then press ESC and type wq to write and quit. To quit without saving, use q.
Using absolute paths and custom SSH ports
For an absolute path on the remote host, include a double slash after the host:
$ vim scp://[email protected]//home/cirdan/Documents/info.txtIf the SSH service runs on a non‑standard port, specify it explicitly:
$ vim scp://[email protected]:2200/info.txtAlternative protocols
If ssh/scp is unavailable, you can use other protocols, e.g.:
$ vim ftp://user@remotesystem/path/to/fileReading and writing remote files from an existing Vim session
When already inside Vim, you can load a remote file with: :e scp://[email protected]/info.txt Or use the NetRead command: :Nread scp://[email protected]/info.txt To see the command’s help, type :Nread ?. To write a remote file, you can use: :w scp://[email protected]/info.txt or the NetWrite command: :Nwrite scp://[email protected]/info.txt Check NetWrite help with :Nwrite ?. After editing, exit Insert mode with ESC and save using :wq or :Nwrite.
Verifying changes on the remote host
To confirm that the remote file was updated, run:
$ ssh [email protected] cat info.txtThese steps provide a complete workflow for editing remote files directly from Vim without leaving the editor.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
