O'Reilly logo

Learning the vi Editor, Sixth Edition by Linda Lamb, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.2. Options When Starting vi

In this handbook, you have invoked the vi editor with the command:

$ vi 
					file 

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.

4.2.1. 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:[1]

[1] According to the POSIX standard, vi should use -c command instead of +command as shown here. Typically, for backwards compatibility, both versions are accepted.

$  

vi +
n file

Opens file at line number n.

$  

vi + 
file

Opens file at last line.

$  

vi +/
pattern file

Opens 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:

KeystrokesResults
vi +/Screen practice Give the vi command with the option +/pattern to go directly to the line containing Screen.

As you see in the example above, your search pattern will not necessarily be positioned at the top of the screen. If you include spaces in the pattern, you must enclose ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required