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

Escape

To create a line below cursor press

o

Create a line above cursor press

Shift + o

To copy a line press

yy

To copy a word press

yw

To copy multiple lines type

Number of lines yy , example  5 yy

To paste copied text in next line press

p

To Paste copied text above line press

Shift + p

To delete a line press

dd

To delete a word press

dw

To undo last change press

u

And to redo last action press

Control + r

To go to end of file press

Shift +g

To go to Start of File press

gg

Show line number

se nu

Hide line numbers

se nonu

Save and exit

wq

Force save and exit

wq!