vi Reference Page

Note: to execute any of the following commands from vi, you must be in command mode
Press the Esc key to enter command mode.

Commands for moving around in a file

Try typing a number in front of these commands and notice what happens


h moves the cursor one character to the left
j moves the cursor down one line
k moves the cursor up one line
l moves the cursor one character to the right
w moves the cursor one “word” forward
b moves the cursor one “word” back
0 (zero) moves the cursor to the beginning of the line
$ moves the cursor to the end of the line
G moves the cursor to the last line in the file
1G moves the cursor to the first line in the file
^d scrolls down 10 lines
^u scrolls up 10 lines
^f page forward one page
^b page back one page

Commands for Reading and Writing out files



:q exits vi if you have saved your changes
:q! exits vi even if you have not saved your changes
:w saves any changes you've made to the file you are editing
:w filename saves your file to a new name (like Save As)
:w! filename saves your file to a new name overwriting any previous data
:r filename reads in the contents of filename starting from the cursor position
:e filename replaces the current content with the content from filename

Different ways of entering Input mode



i Ready to insert characters immediately before the current cursor position
a Ready to append characters immediately after the current cursor position
I Ready to insert characters at the start of the current line
A Ready to append characters at the end of the current line
o Ready to input characters in a new line that opens up below the cursor
O Ready to input characters in a new line that opens up above the cursor
r Ready to replace the current character with the character you type next
R Ready to Replace (overwrite) characters starting at the curent cursor position
s Ready to replace the current character with the string you type next
cw Ready to replace the current word with the string you type next

Cut, Copy, Pasting Commands



x Deletes the current character
dw Deletes the current word
dd Deletes the current line
D Deletes to the end of the line
yy Copies a line to the clipboard buffer
p Pastes whatever is in the clipboard buffer below the current cursor
P Pastes whatever is in the clipboard buffer above the current cursor

Miscellaneous Useful Commands



^g Tells you the filename you are editing and what line your cursor is on
u Undoes the last command you executed
. Repeats the last command you executed
/string Searches for the string of characters in the file
n Finds the next occurrence of the current search string looking down the file
N Finds the next occurrence of the current search string looking up the file
~ Changes the case of the current character