What is VI ?
Visual (VI) is basic text editor work in the command based in Linux, which provide this functionalities as
- Insert, delete, and modify text;
- Copy words, lines, or blocks of text;
- Search and replace characters.
Why should know ?
VI exist in the all the Linux and Unix based operating system, VI is very small and powerful text editor.
How to use ?
Before learn VI command we should know that VI work in three mode
- Command Mode
- Insert Mode
- Ex (Escape) Mode
Command Mode
This is the default mode when any file open and press Esc key to move in the command mode. In this mode all the key is interpreted as command. In this mode we can move cursor up & down, remove text, cut & past etc.
Insert Mode
In this mode we can only write the text and press i or a to move in the insert mode.
Ex Mode
Press colon : to switch in the Ex mode in this mode use to save & exit etc.
Note : To switch Insert Or Ex Mode first switch to the Command mode.
Basic command of the VI
To learn the basic command we follow the journey of the new file create and edit.
- Create the file
vi file_path
vi /doc/new_file
This create new_file on the path and open in command mode
Note : If new_file exist on the location then open without create new.
- Press
iorato switch insert mode. Now can write content as
Happy learning VI
3.Press Esc and then : to switch the Ex mode
now can see the : bottom of the page
press w + Enter save file or
press wq + Enter save file & exit.
Basic command of the VI
Command Mode
Move cursor left:
h or left arrow
Move cursor right:
l or right arrow
Move cursor up:
k or up arrow
Move cursor down:
j or down arrow
Move cursor end of line:
$
Move cursor start of the line:
0
Delete the character at the cursor location:
x
Ex Mode Command
Save the file:
:w
Save file to another name:
:w file_name
Quit editing a file without saving:
:q
Quit editing a file that has been modified during the session but not saved:
:q!
Save the file and exit:
:wq or :x
Save from line n to line m in another file:
:n,m w file_n_to_m_data
Reload the last record of the file:
:e!
Paste the content of another file after the cursor:
:r file_name
Top comments (0)