If you’re searching for info related to the VI editor, this article is for you. So, what’s VI editor? VI is a text editor that’s screen-oriented and the most popular in the Linux world. The reasons for its popularity are 1) availability for almost all Linux distros, 2) VI works the same throughout multiple platforms, and 3) its user-friendly features. Currently, VI Improved or VIM is the most used advanced counterpart of VI.
To work on the VI text editor, you have to know how to use the VI editor in Linux. Let’s find it out from this article.
Modes of VI Text Editor
VI text editor works in two modes, 1) Command mode and 2) Insert mode. In the command mode, users’ commands are taken to take action on a file. The VI editor, usually, starts in the command mode. Here, the words typed act as commands. So, you should be in the command mode while passing a command.
On the other hand, in the Insert mode, file editing is done. Here, the text is inserted into the file. So, you need to be in the insert mode to enter text. Just type ‘i’ to be in the insert mode. Use the Esc key to switch from insert mode to command mode in the editor. If you don’t know your current mode, press the Esc key twice. This takes you to the command mode.
Launch VI Text Editor
First, you need to launch the VI editor to begin working on it. To launch the editor, open your Linux terminal and then type:
And if you mention an existing file, VI would open it to edit. Alternatively, you’re free to create a completely new file.
VI Editing Commands
You need to be in the command mode to run editing commands in the VI editor. VI is case-sensitive. Hence, make sure you use the commands in the correct letter case. Also, make sure you type the right command to avoid undesired changes. Below are some of the essential commands to use in VI.
i – Inserts at cursor (gets into the insert mode)
a – Writes after the cursor (gets into the insert mode)
A – Writes at the ending of a line (gets into the insert mode)
o – Opens a new line (gets into the insert mode)
ESC – Terminates the insert mode
u – Undo the last change
U – Undo all changes of the entire line
D – Deletes the content of a line after the cursor
R – Overwrites characters from the cursor onwards
r – Replaces a character
s – Substitutes one character under the cursor and continue to insert
S – Substitutes a full line and start inserting at the beginning of a line