Vim file management of remote hosts with netrw

From Thomas-Krenn-Wiki
Jump to navigation Jump to search

vi (or vim) is the default editor in many Unix and Linux environments. Vim includes Buildin netrw by default. This allows you to use the application as a file manager. However, this functionality is not limited exclusively to local sources, but can also be used for remote hosts.

This article describes exemplary how to open and edit data records on remote hosts using Vim and netrw.

File access

In the following, the setup and the configuration of the file manager are explained.

Opening the files

In Vim, two sources can be opened at the same time. This can be made with one command in Vim:

vim -c  ":e scp://root@192.168.6.61//" -c ":vsp" -c ":e scp://root@192.168.6.62//"

Please note that the SSH keys are needed for a connection establishment. Otherwise, a password will be requested each time you change folders.


Command declaration

Snippet explanation
vim sets a vim buildin
-c a command follows (command)
":e scp://root@192.168.6.61//" specifies the IP address of the host to which a connection is to be established.
:e edit
scp: securecopy / secure file transfer
vsp ensures that both hosts are displayed in a vertical split screen (VSP)

File editing

If the connection is open, data on both hosts can be edited and compared.

The following describes how to open the files and prepare a comparative editing.

Selection of files

Once the relevant file has been found, it can be selected using the key combination mf.

Then temporarily open them for comparison using the keyboard shortcut md:

Repeat the same process in the other window with the second host. Mark the file with mf as well and open it with md.

Navigation in Vim

With [Strg] + [W] or [P], you can switch between windows or hosts.

Saving of file changes

Changes are written back directly to the respective hosts using

:wa

More information

  • vi (de.wikipedia.org)


Author: Wilfried Seifert

Wilfried Seifert, working in the Systems Engineering department at Thomas-Krenn, is responsible for system/prototype development in his work area. LPIC 3 certified, deals with construction / programming of embedded / GPIO systems; in his spare time he likes to repair old home computers, attends Linux conferences or is on the road with his bike (MTB) for sporting compensation.


Translator: Alina Ranzinger

Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.


Related articles

Bash redirect sdtout and stderr
Linux CPU performance measurements with mpstat
VMware Horizon Linux Client Black Screen