vi has a comprehensive list of commands that can be used to control its activity. Please note, many commands can be prefixed by a number which will cause the command to be repeated that number of times.
e.g. 15dd will delete 15 lines if there are at least 15 lines from cursor to end of the file.

Commands to enter or exit Edit mode
Operation | Keystroke |
---|---|
insert before current position | i |
append after current position | a |
append at end of current line | A |
insert on new line below current | o |
insert on new line above current | O |
replace current character and the insert after | s |
replace current line from start | S |
overwrite character at cursor | r<char> |
overtype (replace) | R |
What you type will appear in the file, either inserted between or replacing the current text.
Operation | Key stroke |
---|---|
end current edit mode | Esc |
You can also end the edit mode by leaving the text area or by moving the cursor outside the edit scope (this depends on which edit mode is being used).
vi Movement Command List
Left | Right | |
---|---|---|
Single Character | h | l |
Word | b | w |
End of Line | ^ | $ |
Up | Down | |
---|---|---|
Line | k | j |
Half a Page | Ctrl+u | Ctrl+d |
Full Page | Ctrl+b | Ctrl+f |
Max | 1G | G |
Deletion Commands
Operation | Key stroke |
---|---|
Delete a character | x |
Delete a word | dw |
Delete an entire line | dd |
List of Miscellaneous commands
Operation | Key stroke |
---|---|
Display line no. and total no of lines | Ctrl+G |
repeat last command | . |
undo last command | u |
yank (copy) word | yw |
yank line | Y |
paste (insert) yanked item after | p |
paste (insert) yanked item before | P |
change case and move one character right | ~ |
join next line onto end of current line | J |
join previous line onto start of current line | K |
move to home position (top right corner) | H |
Search Command
Operation | Key stroke |
---|---|
Find a string | /<string to find> |
Repeat a search forward | n |
List of vi Replace Commands
:%s/<string to replace>/<replacing string>/
optionally, ending with g to do a global replace
vi File Operations
Operation | Key strokes |
---|---|
read file into current file at current location | :r <filename> |
write file to new file name | :w <filename> |
save to current name | :w |
end current edit and start on file named NB. if current file has been changed either write the change, or discard changes | :e <filename> |
discarding changes and restart edit on current file | :e! |
Commands to leave vi
Operation | Key stroke |
---|---|
save any changes made and quit editor | : x :wq ZZ |
quit (no changes made) | :q |
force quit discarding any changes | :q! |