The VI Editor
The vi program is a primitive text editor. It lets you create and modify files. To get into the vi environment from the operating system, type vi fname.
If fname is a previously existing file, it will be brought into vi and you will see it on the screen. If fname does not already exist, this is a way to create it.
Modes:
The vi editor has two modes: text mode and command mode. In text mode, you type in words or numbers. The delete key deletes backspaces over material to the left of the cursor, deleting it -- providing you have just typed that material in. The deleted material doesn't disappear, however, until you enter the command mode. Move from the text mode to the command mode by pressing the escape (esc) key.
In the command mode you can move the cursor around with the arrows. Pressing the (esc) key just rings the bell, telling you that you are in command mode. Pressing the return key moves you to the beginning of the next line. Some other useful commands are
- move the cursor to the beginning of the previous line
$ move the cursor to the end of the current line
G go to bottom of file (move cursor there)
1 G go to line 1
# G go to line #
i insert text to the left of the cursor (gets you into text mode)
x delete character underneath the cursor
dw delete the word to the right of the cursor
db delete the word in back of the cursor
dd delete the current line
D delete everything to the right on the current line
p inserts (puts) everything deleted with the most recent delete command, after the cursor
Typing a number immediately before any of the delete commands will execute the command that many times. For example, 6x deletes the next 6 characters. Deleted material may be placed in named buffers. For example, c6dd deletes the next 6 lines, placing them in buffer c; cp puts the contents of buffer c after the cursor. There are 26 named buffers, a through z. Also,
ZZ exits vi, saving file
:q! quits vi without saving any changes; use this when you mess up
:w fname2 write the file being edited to your directory; create a new file called fname2
/string finds the next occurrence of string
?string finds previous occurrence of string