VI REFERENCE CHEAT SHEET
visual (vi) editor
vi is a command
line editor that is widely-used on Linux/Unix based platforms and is automatically
loaded with virtually all versions of Linux/Unix.
Here are some of the most common
commands to assist you in getting started:
INPUT MODE COMMANDS
i Inserts text before cursor
I Inserts text at the beginning of the
current line
a Appends text after cursor position
A Appends text at the end of the current
line
o Opens a line below
O Opens a line above
DELETE COMMANDS
dw Deletes Word from current position
dd Deletes the entire line
D Deletes from current position to end of
current line
x Deletes character at cursor position
CHANGE TEXT
cw Changes word
cc Changes the line
C Changes to the end of the line
r Replaces the single character under the
cursor
J Joins lines
MOVE CURSOR
e Moves to the end of the word
w Moves to the next word
$ Moves to the end of the line
l Moves one space right
k Moves one line up
j Moves one line down
h Moves one space left
H Moves cursor to the top line on the screen
L Moves cursor to the bottom line on the
screen
M Moves cursor to the middle line on the
screen
^ Moves cursor to the beginning of the line
fx Moves cursor to first occurance of x
MARKING LOCATIONS
mx Marks current position with letter x
`x Moves cursor to mark x
'x Moves cursor to beginning of the line
containing mark x
SCREEN CONTROL
CTRL-d Scrolls forward one-half screen
CTRL-u Scrolls backwards one half screen
CTRL-f Scrolls forward one screen
CTRL-b Scrolls backward one screen
CTRL-l Refreshes screen
z Redraws screen with current
line on top
z- Redraws screen with current line
on bottom
[number]G Places cursor at line number
MOVING TEXT
yy Yanks one line into buffer
p Puts yanked lines below cursor
position
P Puts yanked lines above current
position
ESCAPE OR LAST LINE MODE COMMANDS
:w[file] Writes current buffer as file
:q Quits file
:q! Quits file without saving changes
:wq Writes changes to file and quits
:r[file] Reads file
:e[file] Edits file
:!command Executes a command in the shell
:n Moves to line n
:f Prints out current line and file
name
INFO
CTRL-G Shows size of file, current
filename, and current line
OTHER FUNCTIONS
u Undoes last command
/string Searches forward for string
?string Searches backward for string
n Finds next string
. Repeats last command
ESC Moves from text input mode to command
mode.
**
Note ** Use this to enter Last Line mode
CTRL-V Inserts any character including
special characters
~ Changes character to opposite
case
ZZ Saves file and exits
TIPS
5dd Deletes five lines
10yy Yanks 10 lines
10CTRL-d scrolls down ten lines
QUICK
BASIC TUTORIAL
$vi
new.file - this command is used
at the command line and tells the editor
to open and places you in full screen mode at
which point you
can begin creating the file named new.file
i - to insert text
The
quick brown fox jumped over the lazy dogs back -
text
ESCAPE - to enter last line mode
:wq - to write and exit the file
$ -
back to the command line