You may spend only a small amount of time in an editing session adding new text in insert mode; much of the time you will be making edits to existing text.
In command mode you can position the cursor anywhere in the file. Since you begin all basic edits (changing, deleting, and copying text) by placing the cursor at the text that you want to change, you want to be able to move the cursor to that place as quickly as possible.
There are vi commands to move the cursor:
In Figure 2.1 , an underscore marks the present cursor position. Circles show movement of the cursor from its current position to the position that would result from various vi commands.
You can also use the cursor arrow keys (, , , ) or the [RETURN] and [BACKSPACE] keys, but they are out of the way, and the arrow keys are not supported by all terminals. At first, it may seem awkward to use letter keys instead of arrows for cursor movement. After a short while, though, you'll find it is one of the things you'll like best about vi - you can move around without ever taking your fingers off the center of the keyboard.
Before you move the cursor, press
to make sure that you are in command mode.
You can precede movement commands with numbers.
shows how the command
The ability to multiply commands gives you more options and power for each command you learn. Keep it in mind as you are introduced to additional commands.
When you saved the file practice , vi displayed a message telling you how many lines are in that file. A line is not necessarily the same length as the visible line (limited usually to 80 characters) that appears on the screen. A line is any text entered between newlines. (A newline character is inserted into the file when you press the [RETURN] key in insert mode.) If you type 200 characters before pressing [RETURN] , vi regards all 200 characters as a single line (even though those 200 characters visibly take up several lines on the screen).
As we mentioned,
has an option
that allows you to set
a distance from the right margin at which
insert a newline character. This option is
This command doesn't affect lines that you've already typed. We'll talk more about setting options in Chapter 7, Advanced Editing . (This one really couldn't wait!)
If you do not use
In the example below, line numbers are displayed. (Line numbers can be displayed in
by using the
c ursor , d elete l ines , i nsert c haracters ,
You can also move by word, not counting symbols and punctuation, using the
c ursor, d elete l ines, i nsert c haracters,
To move backward by word, use the
As mentioned previously, movement commands take numeric
arguments; so, with either the
We'll discuss movement by sentences and by paragraphs in Chapter 3, Moving Around in a Hurry . For now, practice using the cursor movement commands that you know, combining them with numeric multipliers.