Vi Editor Cheat Sheet
Starting and Quitting Vi
vi filename - Open a file named 'filename'
:w - Save (write) file
:q - Quit Vi
:wq - Save and quit
:q! - Quit without saving
:w filename - Save file under a new name
Switching Modes
i - Insert before cursor
I - Insert at beginning of line
a - Append after cursor
A - Append at end of line
o - Open a new line below cursor
O - Open a new line above cursor
Esc - Return to Normal mode
Moving Around
h - Move left
l - Move right
j - Move down
k - Move up
0 - Move to beginning of line
$ - Move to end of line
w - Jump forward to start of next word
b - Jump backward to start of previous word
Vi Editor Cheat Sheet
G - Go to end of file
gg - Go to beginning of file
:n - Go to line number n
Editing Text
x - Delete character under cursor
dd - Delete entire current line
dw - Delete from cursor to end of word
D - Delete from cursor to end of line
yy - Copy (yank) current line
yw - Yank current word
p - Paste after cursor
P - Paste before cursor
u - Undo last action
Ctrl + r - Redo undone action
Searching and Replacing
/pattern - Search for pattern forward
?pattern - Search for pattern backward
n - Repeat last search forward
N - Repeat last search backward
:%s/old/new/g - Replace all 'old' with 'new' in file
:n,m s/old/new/g- Replace 'old' with 'new' between lines n and m
Other Useful Commands
:set number - Show line numbers
Vi Editor Cheat Sheet
:set nonumber - Hide line numbers
:syntax on - Enable syntax highlighting
:syntax off - Disable syntax highlighting
:help - Open help documentation