Q: How do I save a file in vi? How do I make changes in vi? How do I move
around in the vi editor?
A:
SUMMARY:
The best way to learn vi is to play around with it, make mistakes and learn
from experience. It is not a very intuitive piece of software for a new user,
but it is extremely useful and included in almost every UNIX flavor. In order
to help you learn vi in this way, this solution will present the vi functions
in chart form and attempt to explain some of the concepts.
1) How to open a file.
2) How to move around within a file.
3) How to save & quit,
4) How to quit without saving.
5) How to search for a string of text.
6) How to edit a file.
DETAILED:
You can open vi in two ways:
1) By typing:
vi {filename}
2) By typing:
vi
In the first case, if the filename exists, it will open that file. If the
file does not exist, it will open a blank file with that name. NOTE: The
file is not yet written to disk.
In the second case, vi just opens with an untitled blank file.
Before you start using vi, you need to know that there are two modes in vi:
1) COMMAND MODE In this mode, characters that you type are are treated as
commands.
2) INPUT MODE In this mode, characters that you type appear in the file
as text input.
When you open vi, you will be in command mode by default.
1) COMMAND MODE COMMONLY USED FUNCTIONS:
move cursor down j
move cursor up k
move cursor left h
move cursor right l
replace current character r
delete current character x
delete current line dd
undo last chance u
delete to end of line D
2) INPUT MODE
To get into input mode, you must press one of the following keys:
insert mode i
append mode a
replace multiple R
NOTE: If you use the arrow keys to move around when you are input mode, you
will notice strange things happening. It will not react as you expect it
to. You must hit ESC to get back into command mode before you can use the
arrows to move around in the file.