VI Editor Cheat Sheet
Modes in VI Editor
- Normal Mode (default) – Used for navigation and command execution.
- Insert Mode – Used for text editing (press
i to enter, Esc to exit).
- Command Mode – Used for saving, quitting, and searching (press
: in Normal mode).
Movement Keys
h – Move left
j – Move down
k – Move up
l – Move right
w – Move forward one word
b – Move back one word
^ – Jump to start of line
$ – Jump to end of line
5G – Go to line 5
1G / gg – Go to first line
G – Go to last line
CTRL+G – Show current line number
gg – Move to the start of the file
G – Move to the end of the file
:n – Move to line number n
Yank (copy)
yy – Copy current line
3yy – Copy next 3 lines
yw – Copy current word
y$ – Copy to end of line
Put (paste)
p – Paste after cursor
P – Paste before cursor
Delete (cut)
dd – Delete current line
3dd – Delete 3 lines
dw – Delete current word
d3w – Delete next 3 words
d4h – Delete 4 characters left
x – Delete a character
X – Delete a character before cursor
d$ – Delete from cursor to end of line
d0 – Delete from cursor to beginning of line
D – Delete from cursor to end of line
u – Undo last action
Ctrl + r – Redo an undone change
Change (delete + insert)
cc – Change current line
cw – Change current word
c3w – Change next 3 words
c5h – Change 5 characters left
Insert Mode Shortcuts
a – Append after cursor
A – Append at the end of the line
i – Insert before cursor
I – Insert start of line
o – Open a new line below
O – Open a new line above
Esc – Exit insert mode
Search and Replace
/word – Search forward
?word – Search backward
n – Next match
N – Previous match
/pattern – Search forward for a pattern
?pattern – Search backward for a pattern
n – Repeat last search forward
N – Repeat last search backward
:%s/old/new/g – Replace all occurrences of "old" with "new"
:s/old/new/g – Replace all occurrences in the current line
Ex Mode (: commands)
:w – Save file
:w filename – Save as new file
:w! – Force save
:e filename – Open file
:1 – Go to line 1
:q – Quit
:q! – Quit without saving
:wq – Save and quit
:x – Save and quit
Working with Multiple Files
:e filename – Open a new file
:w – Save file
:wq – Save and exit
:q! – Quit without saving
:split filename – Split screen horizontally and open another file
:vsplit filename – Split screen vertically
Ctrl + w + w – Switch between split screens