Modes
| Mode | Purpose |
| Normal mode | Navigation and editing commands |
| Insert mode | Typing text |
| Command mode | Save, quit, search, replace |
Open Files
vi file.txt
vi +100 app.log
vi -R config.yml
Insert Mode
| Key | Brief Description |
i | Insert before cursor |
I | Insert at beginning of line |
a | Append after cursor |
A | Append at end of line |
o | Open new line below |
O | Open new line above |
Esc | Leave insert mode |
Save and Exit
:w save
:q quit
:wq save and quit
:x save and quit
:q! quit without saving
Navigation
h j k l left down up right
gg go to top
G go to bottom
:100 go to line 100
Ctrl+d half page down
Ctrl+u half page up
0 start of line
$ end of line
w next word
b previous word
Search
/ERROR
?ERROR
n
N
Edit
dd delete line
5dd delete 5 lines
dw delete word
x delete character
u undo
Ctrl+r redo
Copy and Paste
yy copy line
5yy copy 5 lines
p paste below
P paste above
Replace
r
:s/old/new/g
:%s/old/new/g
:%s/localhost/127.0.0.1/g
Visual Mode
v visual character mode
V visual line mode
d delete selection
y copy selection
Very Practical Log Use
vi app.log
G
/Exception
n
:set number
Minimal Survival Set
i
Esc
:wq
:q!
/text
n
dd
yy
p