Easy Guide to use vi text editor in Linux terminal – Top 20 commands

vi is visual terminal based text editor for linux. vi can open, create and  modify. To use vi text editor in Linux you have to enter vi in status line below text of file. To exit from command mode and enter in text input mode press I. Pressing Escape will make you exit from input mode. Here we have top 20 commands used frequently in vi text editor.

Top 20 command of vi text editor in Linux

Open File in vi text editor

To open a file in vi text editor in current folder type vi filename
In case file exists in different location type path to file followed by file name.


vi /path to file/filename

Modify or Edit files in vi text editor

To enter in Edit mode press i in command mode vi editor. On pressing i you will enter editing mode.

Exit editing mode of vi text editor

Once you are through with editing of File, press Escape key. On pressing Escape key you will enter command mode of vi text editor.

Create new lines in vi text editor

While editing a file using vi text editor in Linux you may need to create a new line, so in order to create new line below cursor enter o in command mode. If you want to create line above cursor press shift+o in command mode.


Create line below cursor


Create line above cursor

Shift + o

Copy Line (Single / Multiple) or Word on vi text editor

vi text editor provides option for coping line from command mode. First take your cursor to Line or word you want to copy.


Copy Line


Copy word


Copy multiple lines

Number of lines yy


To copy 5 line use below command

5 yy

Paste in vi text editor

To Paste content copied earlier, first take your cursor to point where you want to paste text.


To paste copied text in next line press


To paste copied text in line above cursor

Shift + p

Delete line or word in vi text editor

You can delete a line or word from command mode of vi text editor, like before bring your cursor to point you want to delete any content.


To delete a line below cursor


To delete a word press


Undo or redo last change in vi text text editor

Like any other editing application vi text editor also has undo and redo option just enter in command mode vi text editor.


Undo last change


redo last change

Control + r

Navigate in a document in vi text editor

To navigate across file use below commands

Go to end of file press

Shift + g

To go to Start of file press


To go to beginning of a line

o (Zero)

To go to end of line


Show or Hide line number in vi text editor

While scripting its useful have line numbers displayed while you are working on your file.


Show line number

se nu

Hide line numbers

se nonu

Save and Exit from vi text editor

Once you are through with editing of your document in vi text editor, you will need to save before exiting vi text editor. Enter in command mode and use below commands at prompt.


Save file


Save file and quit


quit without saving


Force save and quit


These are few of frequently used commands.

Follow below link for detailed guide on use vi text editor

Detailed Guide to use of vi text editor in Linux