Are you also thinking about what the vi editors are and how to work in the vi editor? If yes, then don't worry because this article is for you. In this article, we will discuss what is a vi editor, its mode of operation, how to use it, its different editing commands, how to move within the file, and how to save it.
So, let's get started.
The default editor that comes with the UNIX operating system is called vi. VI in the vi editor stands for Visual Editor. It is a user-friendly and very powerful application that is available in all Linux distros. An improved version of vi editors is vim.
These are the following reasons why VI editor is popular:
There are two modes of operation of VI editor:
By default, the vi editor starts in the command mode. You have to be present in the insert mode in order to enter the text. For that, just type 'i' and you'll be in insert mode.
When vi starts up, it is in Command Mode. These are the following features of Command Mode:
This mode allows you to insert text into the file. These are the following features of the insert mode:
These are the following steps that are to be followed in order to create a new file:
These are the following VI Editing commands along with their description:
|i||Insert at cursor (goes into insert mode)|
|a||Write after the cursor (goes into insert mode)|
|A||Write at the end of the line (goes into insert mode)|
|ESC||Terminate insert mode|
|u||Undo last change|
|U||Undo all changes to the entire line|
|o||Open a new line (goes into insert mode)|
|3dd||Delete 3 lines.|
|D||Delete contents of the line after the cursor|
|C||Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion.|
|4dw||Delete 4 words|
|x||Delete the character at the cursor|
|R||Overwrite characters from cursor onward|
|s||Substitute one character under cursor continue to insert|
|S||Substitute the entire line and begin to insert at the beginning of the line|
|~||Change case of individual character|
Note: Commands in VI editor are case-sensitive, so it is important to use the commands in the right letter-case.
It is important to be in the command mode in order to move within a file. These are the following default keys for navigation:
Or the arrow keys on the keyboard can also be used for navigation.
It is important to be in the command mode in order to exit the editor and save changes to the file. These are the following ways to save a file:
Let us summarize the above-discussed points for our better understanding: