How to use Linux terminal based text editor vi

vi is visual terminal based text editor for linux. vi can open, create and  modify. To run command you have to enter it 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.

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

To start writing in open file press

i it will start editing mode

To exit from editing mode press


To create a line below cursor press


Create a line above cursor press

Shift + o

To copy a line press


To copy a word press


To copy multiple lines type

Number of lines yy , example  5 yy

To paste copied text in next line press


To Paste copied text above line press

Shift + p

To delete a line press


To delete a word press


To undo last change press


And to redo last action press

Control + r

To go to end of file press

Shift +g

To go to Start of File press


Show line number

se nu

Hide line numbers

se nonu

Save and exit


Force save and exit