5. Introducing the ex EditorContents:
If this is a handbook on vi , why would we include a chapter on another editor? ex is not really another editor. vi is the visual mode of the more general, underlying line editor, ex . Some ex commands can be useful to you while you are working in vi , since they can save you a lot of editing time. Most of these commands can be used without ever leaving vi .[1 ]
You already know how to think of files as a sequence of numbered lines. ex gives you editing commands with greater mobility and scope. With ex you can move easily between files and transfer text from one file to another in a variety of ways. You can quickly edit blocks of text larger than a single screen. And with global replacement you can make substitutions throughout a file for a given pattern. This chapter introduces ex and its commands. You will learn how to:
5.1 ex CommandsLong before vi or any other screen editor was invented, people communicated with computers on printing terminals, rather than on today's CRTs (or bitmapped screens with pointing devices and terminal emulation programs). Line numbers were a way to quickly identify a part of a file to be worked on, and line editors evolved to edit those files. A programmer or other computer user would typically print out a line (or lines) on the printing terminal, give the editing commands to change just that line, then reprint to check the edited line. People don't edit files on printing terminals any more, but some ex line editor commands are still useful to users of the more sophisticated visual editor built on top of ex . Although it is simpler to make most edits with vi , the line orientation of ex gives it an advantage when you want to make large-scale changes to more than one part of a file.
Before you start off simply memorizing ex commands (or worse, ignoring them), let's first take some of the mystery out of line editors. Seeing how ex works when it is invoked directly will help make sense of the sometimes obscure command syntax. Open a file that is familiar to you and try a few ex commands. Just as you can invoke the vi editor on a file, you can invoke the ex line editor on a file. If you invoke ex , you will see a message about the total number of lines in the file, and a colon command prompt. For example: $ You won't see any lines in the file unless you give an ex command that causes one or more lines to be displayed.
ex
commands consist of a line address (which can simply be a
line number) plus a command; they are finished with a carriage return.
One of the most basic commands is : In fact, you can leave off the :
A command without a line number is assumed to affect the current line.
So, for example, the substitute command ( : Notice that the changed line is reprinted after the command is issued. You could also make the same change like this: : 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
To invoke an ex
command from vi
,
you must type the special
bottom line character : Press [RETURN] . Following the exercise, we will discuss ex commands only as they are executed from vi . 5.1.1 Exercise: The ex Editor
|
|