Learning the vi and Vim Editors
Other resources from OReilly
Related titles
vi Editor Pocket Reference
The Productive Programmer
Unix in a Nutshell
Unix Power Tools
Classic Shell Scripting
Mac OS X for Unix Geeks
oreilly.com
oreilly.com is more than a complete catalog of OReilly books.
Youll also find links to news, events, articles, weblogs, sample
chapters, and code examples.
oreillynet.com is the essential portal for developers interested in
open and emerging technologies, including new platforms, pro-
gramming languages, and operating systems.
Conferences
OReilly Media brings diverse innovators together to nurture
the ideas that spark revolutionary industries. We specialize in
documenting the latest tools and systems, translating the inno-
vators knowledge into useful skills for those in the trenches.
Visit conferences.oreilly.com for our upcoming events.
Safari Bookshelf ( safari.oreilly.com ) is the premier online refer-
ence library for programmers and IT professionals. Conduct
searches across more than 1,000 books. Subscribers can zero in
on answers to time-critical questions in a matter of seconds.
Read the books on your Bookshelf from cover to cover or sim-
ply flip to the page you need. Try it today for free.
main.title Page iii Monday, May 19, 2008 11:21 AM
SEVENTH EDITION
Learning the vi and Vim Editors
Tomcat
The Definitive Guide
Arnold Robbins, Elbert Hannah, and Linda Lamb
Jason Brittain and Ian F. Darwin
Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo
Learning the vi and Vim Editors, Seventh Edition
by Arnold Robbins, Elbert Hannah, and Linda Lamb
Copyright © 2008 Arnold Robbins, Elbert Hannah, and Linda Lamb. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles ( http://safari.oreilly.com ). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com .
Editor: Andy Oram
Indexer: Joe Wizda
Production Editor: Sarah Schneider
Cover Designer: Karen Montgomery
Copyeditor: Genevieve dEntremont
Interior Designer: David Futato
Proofreader: Sarah Schneider
Illustrator: Robert Romano
Printing History:
July 2008:
Seventh Edition
November 1998:
Sixth Edition
October 1990:
Fifth Edition
June 1988:
Fourth Edition
August 1987:
Third Edition
April 1986:
Second Edition
February 1986:
First Edition
Nutshell Handbook, the Nutshell Handbook logo, and the OReilly logo are registered trademarks of
OReilly Media, Inc. Learning the vi and Vim Editors , 7th Edition, the image of a tarsier, and related trade
dress are trademarks of OReilly Media, Inc.
Many of the designations uses by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and OReilly Media, Inc. was aware of a
trademark claim, the designations have been printed in
caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-0-596-52983-3
[M]
1215018617
To my wife, Miriam, for your love, patience, and
support.
Arnold Robbins, Sixth and Seventh Editions
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part I. Basic and Advanced vi
1.
The vi Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
A Brief Historical Perspective
5
Opening and Closing Files
6
Quitting Without Saving Edits
10
2.
Simple Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
vi Commands
13
Moving the Cursor
14
Simple Edits
18
More Ways to Insert Text
30
Joining Two Lines with J
31
Review of Basic vi Commands
32
3.
Moving Around in a Hurry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Movement by Screens
35
Movement by Text Blocks
38
Movement by Searches
39
Movement by Line Number
43
Review of vi Motion Commands
44
4.
Beyond the Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
More Command Combinations
47
Options When Starting vi
48
Making Use of Buffers
51
Marking Your Place
52
Other Advanced Edits
53
Review of vi Buffer and Marking Commands
53
vii
5.
Introducing the ex Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
ex Commands
55
Editing with ex
58
Saving and Exiting Files
63
Copying
a File into Another File