$ vi filename
Note: To move to the command mode press ESC.
Basic commands for text insertion:
i – Insert text before the cursor
a – Insert text after the cursor
r – Insert text at the beginning of the line where the cursor is
A – Insert text at the end of the line where the cursor is
o – Add row below the current row
O – Add line above the current line
Ctrl + h – Delete the last character
Basic command drive:
Ctrl + f – Move the cursor to the next screen
Ctrl + b – Move the cursor to the previous screen
H – Move the cursor to the first line of the screen
M – Move the cursor to the middle of the screen
L – Move the cursor to the last line of the screen
h – Move the cursor one character to the left
j – Move the cursor to the next line
k – Move the cursor to the previous line
l – Move the cursor one character right
w – Move the cursor to the beginning of the next word (Ignore punctuation)
W – Move the cursor to the beginning of the next word (Not ignores the punctuation)
b – Move the cursor to the beginning of the previous word (Ignore punctuation)
B – Move the cursor to the previous word beginning (Not ignores the punctuation)
0 – Moves the cursor to the beginning of the current line
^ – Move the cursor to the first non blank character of the current line
$ – Move the cursor to the end of the current line
G – Move the cursor to the last line of the file
nG – Move the cursor to the line n
Basic commands to find text:
/ Word – search by word or character in all text
? Word – Move the cursor to the previous word occurrence
n – Repeats the last command / or?
N – Repeats the last command / or? In the reverse direction
Ctrl + g – Shows the file name, the number of the current line and total lines
Basic commands for text alteration:
x – Deletes the character that is under the cursor
dw – Deletes the word, the current cursor position until the end
dd – Deletes the current line
D – Deletes the line from the current cursor position until the end
rx – Replaces the character under the cursor by the specified x (indicate the character is optional)
Rx – Replaces the word under the cursor indicated by the word x
u – Undo the last modification
U – Undo all the modifications made in the current line
J – Joins current line next
s: /word1/word2 – Replaces first occurrence of “word1” by “word2”
Command to save the text:
:Wq – Save the file and exit the editor
:W filename – Saves the current file with the specified name
:W! filename – Saves the current file to the specified file
:Q – Quits editor
:Q! – Exit the editor without saving the performed alterations