Options When Starting vi
So far, you have invoked the vi editor with the command:
$vifile
There are other options to the vi command that can be helpful. You can open
a file directly to a specific line number or pattern. You can also
open a file in read-only mode. Another option recovers all changes to
a file that you were editing when the system crashed.
Advancing to a Specific Place
When you begin editing an existing file, you can call the file in and then move to the first occurrence of a pattern or to a specific line number. You can also specify your first movement by search or by line number right on the command line:[15]
$vi +n fileOpens file at line number n.
$vi +fileOpens file at last line.
$vi +/pattern fileOpens file at the first occurrence of pattern.
In the file practice, to open the file and advance directly to the line containing the word Screen, enter:
| Keystrokes | Results |
vi +/Screen practice | With a screen editor you can scroll
the page, move the cursor, delete
lines, and insert characters, while
seeing the results of your edits as
you make them.Screen editors are
very popular, since they allow you
to make changes as you read Give the |
As you see in this example, your search pattern will not necessarily be positioned at the top of the screen. If you include spaces in the pattern, you must enclose the whole pattern within single or double quotes:[16]
+/"you make"
or escape the space with ...