- 论坛徽章:
- 0
|
scroll the page, move the cursor,
delete lines, insert characters, and more,
A command without a line number is assumed to affect the current
line. So, for example, the substitute command (s), which allows you
to substitute one word for another, could be entered like this:
:1
With a screen editor you can
:s/screen/line/
With a line editor you can
Notice that the changed line is reprinted after the command is
issued. You could also make the same change like this:
:1s/screen/line/
With a line editor you can
Even though you will be invoking ex commands from vi and will not
be using them directly, it is worthwhile to spend a few minutes in ex
itself. You will get a feel for how you need to tell the editor which
line (or lines) to work on, as well as which command to execute.
After you have given a few ex commands on your practice file, you
should invoke vi on that same file, so that you can see it in the
more familiar visual mode. The command :vi will get you from ex
to vi.
To invoke an ex command from vi, you must type the special
bottom line character : (colon). Then type the command and press
RETURN to execute it. So, for example, in the ex editor you move to
a line simply by typing the number of the line at the colon prompt.
To move to line 6 of a file using this command from within vi, enter:
:6
Press RETURN.
Following the exercise, we will discuss ex commands only as they
are executed from vi.
5.1.1 Exercise: The ex Editor
At the UNIX prompt, invoke ex editor on a file
called practice: ex practice
A message appears: "practice" 6 lines, 320characters
Go to and print (display) first line: :1
Print (display) lines 1 through 3: :1,3 |
|