Matt's Hectic VI HACKING Made Easy

"Most Non-Unix managers conclude that VI is either extraterrestrial in origin or was devised by the original Unix developers as part of a secret communications code to reach another dimension."
- Communications Week - July 26, 1993.

[Navigation] [Input Modes] [Files] [Cut, Copy, & Paste] [Repetition] [Search & Replace]

Cursor Positioning & Navigation
j Down One Line
k Up One Line
h Left One Character
l Right One Character
0 Beginning of Line
$ End of Line
w Forward One Word
b Beginning of the Current Word
e End of the Current Word
H Top of Screen (think HIGH)
L Bottom of Screen (think LOW)
M Middle of Screen
Ctrl-U Page Up
Ctrl-DPage Down
G Bottom of File (last line)
1G Top of File (first Line)

Text Input Modes
i Insert to the Left of the Cursor
a Append after the Cursor
I Insert at the Beginning of the Current Line
A Append after the End of the Current Line
O Start Text on a New Line Above this one
o Start Text on a New Line Below this one
r Overstrike the Current Character
R Overstrike Until you hit Escape
cw Change Word
C Change from Here to End of the Line
~ Change Case

File Commands
:w Save the Current File
:x Write to Current Filename and Quit
:x filename Write to a New Filename and Quit
:q! Quit without saving
:e filename Edit a File without exiting VI
:r filename Read in a File after the cursor
ZZ Save and Quit (same as :x, but with fewer finger movements!)

Cut, Copy, & Paste
x Delete One Character
dw Delete One Word
dd Delete One Line
dX d followed by any of the Navigation Tools will delete all the text between the current cursor position and the navigated place.
dt letter d Delete to first instance of letter in line.
dT letter d Delete to first instance of letter in line.
yyCopy the current line
p PASTE!!!!!!
Moving a Block of Text
  1. Position the Cursor at the beginning of the block
  2. Mark the position by hitting mx
  3. Position the Cursor at the End of the block
  4. Delete the Block by typing d`x
  5. Copy the Block by typing y`x
  6. Paste the block using the standard VI paste, p

Period (.) will repeat the last command
Most VI commands can be preceded by a number, to do them multimple times.

Search and Replace
/word Searches for a Word, Forward from the current position
?word Searches for a Word, Back from the current position
n Repeat Last Find
N Repeat Last Find in the Opposite Direction
:g/word/s//newword/g Replace Word with New Word in the WHOLE File
f letter Goes to first instance of letter in that line
F letter Goes backwards to first instance of letter in that line

Back to the UNIX Help Screen
Back to Matt's Home Page

Matthew A d'Alessio / University of California, Berkeley