material, most of the editing was done with Vim versions 4.5 and 5.0 under GNU/Linux
(Red Hat 4.2).
Thanks to Keith Bostic, Steve Kirkendall, Bram Moolenaar, Paul Fox, Tom Dickey, and
Kevin Buettner, who reviewed the book. Steve Kirkendall, Bram Moolenaar, Paul Fox,
Tom Dickey, and Kevin Buettner also provided important parts of Chapters 8 through
12. (These chapter numbers refer to the sixth edition.)
Without the electricity being generated by the power company, doing anything with a
computer is impossible. But when the electricity is there, you dont stop to think about
it. So too when writing a bookwithout an editor, nothing happens, but when the
editor is there doing her job, its easy to forget about her. Gigi Estabrook at OReilly is
Preface | xix
a true gem. Its been a pleasure working with her, and I appreciate everything shes
done and continues to do for me.
Finally, many thanks to the production team at OReilly & Associates.
Arnold Robbins
Raanana, ISRAEL
June 1998
Acknowledgments for the Seventh Edition
Once again, Arnold thanks his wife, Miriam, for her love and support. The size of his
quiet time and ice cream debt continues to grow. In addition, thanks to J.D. Illiad
Frazer for the great User Friendly cartoons.
Elbert would like to thank Anna, Cally, Bobby, and his parents for staying excited about
his work through the tough times. Their enthusiasm was contagious and appreciated.
Thanks to Keith Bostic and Steve Kirkendall for providing input on revising their edi-
tors
chapters. Tom Dickey provided significant input for revising the chapter on
vile and the table of set options in Appendix B. Bram Moolenaar (the author of Vim)
reviewed the book this time around as well. Robert P.J. Day, Matt Frye, Judith Myerson,
and Stephen Figgins provided important review comments throughout the text.
Arnold and Elbert would both like to thank Andy Oram and Isabel Kunkle for their
work as editors, and all of the tools and production staff at OReilly Media.
Arnold Robbins
Nof Ayalon, ISRAEL
2008
Elbert Hannah
Kildeer, Illinois USA
2008
See http://www.userfriendly.org if youve never heard of User Friendly .
xx | Preface
PART I
Basic and Advanced vi
Part I is designed to get you started quickly with the vi editor and to provide the ad-
vanced skills that will let you use vi most effectively. These chapters cover the original,
core vi and provide commands you can use on any version; later chapters cover popular
clones. This part contains the following chapters:
Chapter 1, The vi Text Editor
Chapter 2, Simple Editing
Chapter 3, Moving Around in a Hurry
Chapter 4, Beyond the Basics
Chapter 5, Introducing the ex Editor
Chapter 6, Global Replacement
Chapter 7, Advanced Editing
Chapter 8, Introduction to the vi Clones
CHAPTER 1
The vi Text Editor
Unix* has a number of editors that can process the contents of text files, whether those
files contain data, source code, or sentences. There are line editors, such as ed and ex,
which display a line of the file on the screen; and there are screen editors, such as vi
and Emacs, which display a part of the file on your terminal screen. Text editors based
on the X Window System are also commonly available and are becoming increasing
popular. Both GNU Emacs and its derivative, XEmacs, provide multiple X windows;
two interesting alternatives are the sam and Acme editors from Bell Labs. Vim also
provides an X-based interface.
vi is the most useful standard text editor on your system. (vi is short for visual editor
and is pronounced vee-eye. This is illustrated graphically in Figure 1-1.) Unlike Emacs, it is available in nearly identical form on every modern Unix system, thus providing a kind of text-editing lingua franca . The same might be said of ed and ex, but
screen editors are generally much easier to use. (So much so, in fact, that line editors
have generally fallen into disuse.) With a screen editor, you can scroll the page, move
the cursor, delete lines, insert characters, and more, 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 through a file, like you would edit a printed copy, only faster.
To many beginners, vi looks unintuitive and cumbersomeinstead of using special
control keys for word processing functions and just letting you type normally, it uses
all of the regular keyboard keys for issuing commands. When the keyboard keys are
issuing commands, vi is said to be in command mode . You must be in a special insert
mode before you can type actual text on the screen. In addition, there seem to be so
many commands.
* These days, the term Unix includes both commercial systems derived from the original Unix code base,
and Unix work-alikes whose source code is available. Solaris, AIX, and HP-UX are examples of the former,
and GNU/Linux and the various BSD-derived systems are examples of the latter. Unless otherwise noted,