The commands you type in command mode
To add text to your file, use a vi command such as i. What you type in insert mode:
Back to Index
Creating and Editing a file
To insert new text into a new or existing file, follow these steps:
vi filenameand then press the RETURN key. (Replace filename with the name of the file that you want to create or edit).
iDo not press the RETURN key.
The "i" will not appear on the screen; it is a command that indicates you want to insert text.
Back to Index
Saving a file
When you are done
adding or editing text in the file and you want to save the file,
press the ESCAPE key. You will return to command mode. To save your file,
type
:wqYou should see the UNIX prompt (%) again.
Back to Index
Command mode commands
File saving and Loading
:e filename | edit new file filename |
:r filename | read in contents of filename |
:q | quit editing |
:q! | quit editing and discard changes |
:wq | write file and quit |
:w filename | write to the file named filename |
:w | write to the file already named |
:w! filename | overwrite the file filename |
Back to Index
Insert mode commands (text entry)
a | append text, after the cursor position |
A | append text to end of the line |
i | insert text, before the cursor position |
I | insert text at the beginning of the line |
o | open new line below cursor, enter insert mode |
O | open new line above cursor, enter insert mode |
R | enter overstrike mode, press the ESCAPE key to exit |
Press the ESCAPE key to exit insert mode.
/text | search forward for first occurrence of text |
?text | search backward for first occurrence of text |
Back to Index
Cursor control commands
b | go to beginning of word |
e | go to end of word |
G | go to the last line of the file |
##G | go to the ##th line of the file |
h | move left one character |
j or RETURN | move down one line |
k | move up one line |
l or SPACEBAR | move right one character |
{ | move to the previous paragraph |
} | move to the next paragraph |
$ | move to the end of the line |
^ | move ot the beginning of the line |
Back to Index
Basic text manipulation commands
dd | delete one line (place in general buffer) |
dj | delete current line and one below |
d} | delete up to the end of the paragraph |
D | delete the rest of the line |
J | join two lines |
r | replace character on which the cursor rests |
s | enter insert mode to substitute text for the character on which the cursor rests |
##s | substitute ## characters, enter insert mode |
u | undo the last change |
x | delete one character |
##x | delete ## characters |
Back to Index
Advanced text manipulation commands
"ap | same as p but from buffer "a" |
"aP | same as P but from buffer "a" |
"ay | yank line into the buffer named "a" |
cw | deletes word starting at the cursor, enter insert mode |
p | put contents of general buffer after current line |
P | put contents of general buffer before current line |
yy | yank line into the general buffer |
##yy | yank ## lines into general buffer |
##yl | yank ## characters to left of cursor |
> | shift line right |
< | shift line left |
Back to Index
Miscellaneous commands
CONTROL-G | print information about file: name, current line number |
:## | go to the line numbered ## |
:%s/pattern/text/ | substitute first occurrence of pattern on each line with text |
:%s/pattern/text/g | substitute every occurrence of pattern with text |
:g/pattern/d | delete every line containing pattern |
:10,50 ya | yank the contents of lines 10 through 50 and place in the general buffer |
:%!sort | execute the UNIX command sort on every line, replace contents with output of command |