Basic commands for the VI editor

When you need to edit files on an ESXi host directly or on a Linux-host, such as the vCenter appliance, then it is a useful skill to be able to use the VI-editor. In this article I describe the absolute basics you need to know.

The easiest way to open a file with the VI-editor is to start the program with the filename of the file to edit as a parameter. Such as this:

vi /etc/udev/rules.d/70-persistent-net-rules

With this command the editor starts and opens the file. In the next image you can see how your screen would look like. 

Using VI editor

You can now scroll through the file with the arrow-keys, page-up, page-down, down and end. In the right corner at the bottom you can see on which line and column you are in the file. 

In this browsing mode you can easily delete an entire line with the command dd. Just type dd and the current line will be deleted. 

When you want to edit the contents of the file use the Insert-key to switch to the editing mode. This key is a toggle between Insert and Replace. You can see the status of the editor in the bottom left-corner.

Using VI editor

Using VI editor

When you are done editing press the Esc-key. The indicator at the bottom left corner will disappear and you can again scroll through the file.

When you want to save the file and/or exit the editor press the colon-key (:)

Using VI editor

In this command mode you can enter commands such as w to write changes to the file system or q to quit. And how about h for help?

 In the command mode (:) you can also type syntax off to disable the color coding of the text.

If you did not make any changes then just enter q and press enter. If you did make changes then first type w and press enter to write the changes to the file system.

It is also possible to combine commands such as wq to write and quit. If you try to quit the editor without first saving any changes then you would see the message below. To quit without writing changes type q! and press enter. 

Using VI editor

If you did not find what you need in this article a complete manual for the VI-editor can be found here:


Follow us on LinkedIn




Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer