Chapter 5. Introducing the ex Editor

If this is a book on vi and Vim, why would we include a chapter on another editor? Well, ex is not really another editor. vi is the visual mode of the more general, underlying line editor, which is 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: You can think of the ex command line as a third mode, alongside the regular command and insert modes.

The various vi motion and text-modification commands we’ve seen in the previous chapters are nice, but if that’s all you’ve got, you may as well use Notepad or something similar. The reason vi lovers love vi is because of ex: ex is where the power is!

Note

Vim provides the underlying ex editor, with many enhancements over the original one. On systems where vi is Vim, ex usually also invokes Vim in ex mode.

In this and the following chapters in Part I, we don’t distinguish much between vi and Vim, since everything in these chapters applies to both. While reading, feel free to think of “vi” as standing for “vi and Vim.”

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 ...

Get Learning the vi and Vim Editors, 8th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.