vi is a powerful editor with many features. It can handle very large files much easier than a program like Microsoft Word. Unlike Word, vi is only a TEXT EDITOR and you cannot include graphics or fancy fonts in your file.
Although there are lots of different commands in vi, it is possible to get started using vi knowing only a small subset of them. As you feel more comfortable with vi, you can learn the more advanced features.
vi has 3 modes:
Remember, in vi, the mouse cannot be used to issue editor commands or move the cursor.
This is also similar to the GCG sequence editor SeqEd, which has a command mode and an editing mode. It's best to use programs like GCG's SeqLab Editor to edit the sequences instead of using vi or a Word Processor. If you do edit a GCG sequence, then run the program reformat before using the sequence.
When you first enter the editor, you are in the command mode. To enter the write mode, type the letter a for append. This is one of the four possible commands for entering the write mode. vi is Case Sensitive. Lower case commands are different from upper case commands.
You are in command mode whenever you hit esc to leave the write mode. In command mode, you can move the cursor anywhere in the file.
The x key deletes individual characters, while dd deletes an entire line. To enter the insert mode type the i key. When you're done inserting, hit the "esc" key to return to the command mode.
Command-line mode is used for such things as writing changes and exiting the editor. To enter command-line mode, type : while in command mode. The : will now appear at the bottom of the screen and the command which you type will appear on that line.
EXAMPLE:
% vi practice
In this example, the new file "practice" is created if it doesn't already exist.
The screen will look like this after opening a new file entitled, "practice".
============================================================= ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "practice" [New File] =============================================================
Once in vi, you are placed in the command mode. You cannot enter text in this mode. If you try, the letters you try to type will not appear on the screen. This is because ordinary letters are interpreted as commands.
You must enter the edit mode to type text.
To do so, use one of the following commands. The vi text editor is case sensitive, which means the same letters in upper and lower case have different command responses.
|
What to Type |
|
a |
append after the cursor |
i |
insert before the cursor |
The "esc" key must be used to end any of the above commands or to begin any of the following commands (depending on which way you look at it). You must also hit the "esc" key prior to any cursor movement. When in doubt, hit the "esc" key and proceed.
|
What to Type |
|
x |
deletes the character the cursor is under |
dd |
deletes the line the cursor is on |
In the command mode, it is possible to move the cursor up, down, left or, right by using the arrow keys on the keyboard. However, no matter what type of keyboard you have, it is possible to use the vi commands, h, j, k, and l, all in lowercase, to control the cursor.
These commands move the cursor as follows:
|
What to Type |
|
j |
moves the cursor up one line |
k |
moves the cursor down one line |
h |
moves the cursor backwards on a line |
l |
moves the cursor forward on a line |
To cut and paste, I usually use the Mac commands instead of the vi commands. These work with NCSA Telnet. Just select the text to copy with your mouse, then move the cursor using the arrow keys (not the mouse) over to the area you want to paste the text, then make sure you are in the "insert" or "append" mode and then paste the text using the Macintosh command (Command-v).
First you need to enter the command mode by
pressing the Escape key.
Now you are ready to give any one of a number of line
commands.
|
What to Type |
|
:wq |
saves the current changes and exits vi |
:w! |
saves the current changes but does not exit vi |
:q! |
exits vi without saving any change |
Other popular command include
What to type
What it does
Deletes n number of lines
Go to start of line
Copy n number of lines
go to end of line
goes to top of file
goes to fifth line of file
goes to bottom of file
will number all your lines
turn off line numbering
Global substitutions
There are many different vi tutorials out on the internet, if you need more help, check out some of these.
Cornell
Theory Center Tutorial
UCS
Tutorial
Command
List
vi Quick
Reference
Or you can check out the man pages for vi