How to use VI

viI like to use VI instead of other editors. It’s simple and easy to use and available on almost every Unix system. VI is also very powerfull when you learn more about it, but i’ll only explain the basics here.

Good to know: VI has 2 command modes: command mode and insert mode. Insert mode is for typing.
When you start VI by entering vi in the terminal, you’ll start in command mode.
Press i to enter command mode and ESC to get back to command mode.

For example if you want to edit a file located in: /etc/var/example enter:
vi /etc/var/example
If the file doesnt exist, it will create one.

In my tutorials I use VI a lot, so here are some basic commands:

Command mode:
i – Entering insert mode
ESC – get back to command mode
x – delete a character
shift + x – delete the character before the cursor
dd – delete the whole line
shift + a – Get to the last character on the line and enter insert mode
u – undo
/ – enter what you want to search and hit ENTER
:q! – quit without saving
ZZ (shift +zz) – save and quit

Insert mode:
ESC – exit insert mode