How to exit Vim: A Quick Start Guide
Open file to edit
vi <file_name>
Enter the edit mode
i
Enter the edit mode with the cursor at the beginning of the file
I
Press the / key to search string
/
Autocomplete texts that are already written
CRTL + n
Move to the first line
gg
Move to the last line
G
Move left, down, up, right
h, j, k, l
Move word to word in the right direction
w
Move word to word in the left direction
b
Combine w or b with d to delete the current word
w | b
Delete the current line
dd
Copy the current line
yy
Paste the copied/yanked content on the current line
p
Swap two consecutive lines
ddp
Duplicate a line
yyp
Repeat the last operation. VERY IMPORTANT.
.
Indent the current line on the right
shift + >>
Index the current line on the left
shift + <<
Finds and moves the cursor on the character we are looking for
f + <character_to_search>
Put the cursor on the character to replace and then press “r” and the new character
r + <character_to_replace_by>
Put the cursor on the string to replace and the press “R” and start typing the new string
R + <string_to_replace_by>
Select text character by character, which you can copy or delete or replace with some text.
v
Select text line by line.
V
Press the Esc key to get out of edit mode
Esc
Exit vi without saving
:q!
Exit vi and save
:wq