|
vi QuickStart
Copyright (C) 2004 by Gary E. Christensen
Starting vi
From the command prompt, type vi and press
the enter key. Or, to edit a specific file, type vi,
then a space, then the filename,
then the enter key.
Examples:
vi <enter> |
Starts vi with no text file name. |
vi example.c <enter> |
Starts vi editing the file example.c. If example.c does
not exist it will be created when the file is saved. |
Quitting vi
From inside vi, type ZZ (shift zz) to save
changes and quit. To quit vi without saving the chages type ":q!"
without the quotes followed by the enter key.
ZZ |
save file and quit. |
:wq <enter> |
save file and quit. |
:q <enter> |
Quit without saving. Gives an error message if the file
has been modified since its last save. |
:q! <enter> |
Quit without saving and without a warning message that
the file was changed. |
Editing in vi
There are two modes in vi: command mode and edit mode. vi
begins in command mode. To move the curser around use the arrow keys or
the h, j, k, and l keys. To enter text from the command mode, first
type "i" to insert, which is part of the text entry
mode. Then, start typing to enter text before the cursor. Hit the escape
key to return to the command mode.
arrow keys |
move cursor around in vi. |
h, j, k, and l keys |
move cursor around in vi. |
i |
insert at current cursor location. |
a |
insert one character after cursor location (append
mode). |
A |
insert at end of current text line. |
o |
creates a new line for editing below current line. |
O |
creates a new line for editing above current line. |
x |
delete character under cursor. |
dw |
delete the characters to the end of the word starting
from the current cursor location. |
escape key |
IMPORTANT: returns from edit mode to command
mode. |
<number> G |
go to line number specified by number. |
G |
go to last line of program. |
1 G |
go to first line of program. |
/string |
search from current location in file to the end of the
file and stop when finding the first occurance of string. |
n |
find the next occurance of the search string specified
by the previous "/string" command.
|
u |
undo the previous command. |
. |
typing a period repeats the previous command. |
:1,$ s/string1/string2/ <enter> |
The first occurance of string1 on each line in the
program is replaced with string2. |
:1,$ s/string1/string2/g <enter>
|
Replaces all occurances of string1 are replaced by
string2. |
|