vi filename — To start editing file filename
e.g. vi test.txt
u — undo the last command
j — Moves cursor down one line, same column
k — Moves cursor up one line, same column
h — Moves cursor back one character
l — Moves cursor forward one character
0 — Moves cursor to beginning of current line
$ — Moves cursor to end of current line
b — Moves the cursor backward to the beginning of the previous word
e — Moves the cursor backward to the end of the previous word.
w — Moves the cursor forward to the next word
a — Appends text after cursor. Terminated by escape key.
A — Appends text at the end of the line. Terminated the escape key.
i — Inserts text before cursor. Terminated by the escape key.
I — Inserts text at the beginning of the line. Terminated by the escape key.
o — Opens new line below the current line for text insertion. Terminated by the escape key
O — Opens new line above the current line for text insertion. Terminated by the escape key.
ESC — Stops text insertion
x — Deletes current character.
dd — Deletes current line
dw — Deletes the current word.
P — Puts back text from the previous delete.
yy — Puts the current line in a buffer. Does not delete the line from its current position.
p — Places the line in the buffer below the current position of the cursor.
P — Places the line in the buffer above the current position of the cursor.
ZZ — Exits vi and saves changes.
q! — Exit vi without saving text.
::%s/search/replace/g — search and replace particular pattern.
e.g. :%s/windows/linux/g will replace the all the occurance of windows by linux in the file.
:%s/$/\r insert new line after each line in a file.
:v/./d remove blank lines from a file.
:r <filename> read in a new file at the current location