You are previewing Learning the vi and Vim Editors, 7th Edition.

Learning the vi and Vim Editors, 7th Edition

Cover of Learning the vi and Vim Editors, 7th Edition by Arnold Robbins... Published by O'Reilly Media, Inc.
  1. Dedication
  2. Special Upgrade Offer
  3. Preface
    1. Scope of This Book
    2. How the Material Is Presented
      1. Discussion of vi Commands
      2. Conventions
      3. Keystrokes
      4. Problem Checklist
    3. What You Need to Know Before Starting
    4. Comments and Questions
    5. Safari® Books Online
    6. About the Previous Editions
    7. Preface to the Seventh Edition
      1. What’s New
      2. Versions
      3. Acknowledgments from the Sixth Edition
      4. Acknowledgments for the Seventh Edition
  4. I. Basic and Advanced vi
    1. 1. The vi Text Editor
      1. A Brief Historical Perspective
      2. Opening and Closing Files
      3. Quitting Without Saving Edits
    2. 2. Simple Editing
      1. vi Commands
      2. Moving the Cursor
      3. Simple Edits
      4. More Ways to Insert Text
      5. Joining Two Lines with J
      6. Review of Basic vi Commands
    3. 3. Moving Around in a Hurry
      1. Movement by Screens
      2. Movement by Text Blocks
      3. Movement by Searches
      4. Movement by Line Number
      5. Review of vi Motion Commands
    4. 4. Beyond the Basics
      1. More Command Combinations
      2. Options When Starting vi
      3. Making Use of Buffers
      4. Marking Your Place
      5. Other Advanced Edits
      6. Review of vi Buffer and Marking Commands
    5. 5. Introducing the ex Editor
      1. ex Commands
      2. Editing with ex
      3. Saving and Exiting Files
      4. Copying a File into Another File
      5. Editing Multiple Files
    6. 6. Global Replacement
      1. Confirming Substitutions
      2. Context-Sensitive Replacement
      3. Pattern-Matching Rules
      4. Pattern-Matching Examples
      5. A Final Look at Pattern Matching
    7. 7. Advanced Editing
      1. Customizing vi
      2. Executing Unix Commands
      3. Saving Commands
      4. Using ex Scripts
      5. Editing Program Source Code
    8. 8. Introduction to the vi Clones
      1. And These Are My Brothers, Darrell, Darrell, and Darrell
      2. Multiwindow Editing
      3. GUI Interfaces
      4. Extended Regular Expressions
      5. Enhanced Tags
      6. Improved Facilities
      7. Programming Assistance
      8. Editor Comparison Summary
      9. Nothing Like the Original
      10. A Look Ahead
  5. II. Vim
    1. 9. Vim (vi Improved): An Introduction
      1. Overview
      2. Where to Get Vim
      3. Getting Vim for Unix and GNU/Linux
      4. Getting Vim for Windows Environments
      5. Getting Vim for the Macintosh Environment
      6. Other Operating Systems
      7. Aids and Easy Modes for New Users
      8. Summary
    2. 10. Major Vim Improvements over vi
      1. Built-in Help
      2. Startup and Initialization Options
      3. New Motion Commands
      4. Extended Regular Expressions
      5. Customizing the Executable
    3. 11. Multiple Windows in Vim
      1. Initiating Multiwindow Editing
      2. Opening Windows
      3. Moving Around Windows (Getting Your Cursor from Here to There)
      4. Moving Windows Around
      5. Resizing Windows
      6. Buffers and Their Interaction with Windows
      7. Playing Tag with Windows
      8. Tabbed Editing
      9. Closing and Quitting Windows
      10. Summary
    4. 12. Vim Scripts
      1. What’s Your Favorite Color (Scheme)?
      2. Dynamic File Type Configuration Through Scripting
      3. Some Additional Thoughts About Vim Scripting
      4. Resources
    5. 13. Graphical Vim (gvim)
      1. General Introduction to gvim
      2. Customizing Scrollbars, Menus, and Toolbars
      3. gvim in Microsoft Windows
      4. gvim in the X Window System
      5. GUI Options and Command Synopsis
    6. 14. Vim Enhancements for Programmers
      1. Folding and Outlining (Outline Mode)
      2. Auto and Smart Indenting
      3. Keyword and Dictionary Word Completion
      4. Tag Stacking
      5. Syntax Highlighting
      6. Compiling and Checking Errors with Vim
      7. Some Final Thoughts on Vim for Writing Programs
    7. 15. Other Cool Stuff in Vim
      1. Editing Binary Files
      2. Digraphs: Non-ASCII Characters
      3. Editing Files in Other Places
      4. Navigating and Changing Directories
      5. Backups with Vim
      6. HTML Your Text
      7. What’s the Difference?
      8. Undoing Undos
      9. Now, Where Was I?
      10. What’s My Line (Size)?
      11. Abbreviations of Vim Commands and Options
      12. A Few Quickies (Not Necessarily Vim-Specific)
      13. More Resources
  6. III. Other vi Clones
    1. 16. nvi: New vi
      1. Author and History
      2. Important Command-Line Arguments
      3. Online Help and Other Documentation
      4. Initialization
      5. Multiwindow Editing
      6. GUI Interfaces
      7. Extended Regular Expressions
      8. Improvements for Editing
      9. Programming Assistance
      10. Interesting Features
      11. Sources and Supported Operating Systems
    2. 17. Elvis
      1. Author and History
      2. Important Command-Line Arguments
      3. Online Help and Other Documentation
      4. Initialization
      5. Multiwindow Editing
      6. GUI Interfaces
      7. Extended Regular Expressions
      8. Improved Editing Facilities
      9. Programming Assistance
      10. Interesting Features
      11. elvis Futures
      12. Sources and Supported Operating Systems
    3. 18. vile: vi Like Emacs
      1. Authors and History
      2. Important Command-Line Arguments
      3. Online Help and Other Documentation
      4. Initialization
      5. Multiwindow Editing
      6. GUI Interfaces
      7. Extended Regular Expressions
      8. Improved Editing Facilities
      9. Programming Assistance
      10. Interesting Features
      11. Sources and Supported Operating Systems
  7. IV. Appendixes
    1. A. The vi, ex, and Vim Editors
      1. Command-Line Syntax
      2. Review of vi Operations
      3. vi Commands
      4. vi Configuration
      5. ex Basics
      6. Alphabetical Summary of ex Commands
    2. B. Setting Options
      1. Solaris vi Options
      2. nvi 1.79 Options
      3. elvis 2.2 Options
      4. Vim 7.1 Options
      5. vile 9.6 Options
    3. C. Problem Checklists
      1. Problems Opening Files
      2. Problems Saving Files
      3. Problems Getting to Visual Mode
      4. Problems with vi Commands
      5. Problems with Deletions
    4. D. vi and the Internet
      1. Where to Start
      2. vi Web Sites
      3. A Different vi Clone
      4. Amaze Your Friends!
      5. Tastes Great, Less Filling
      6. vi Quotes
  8. Index
  9. About the Authors
  10. Colophon
  11. Special Upgrade Offer
  12. Copyright
O'Reilly logo

Editing with ex

Many ex commands that perform normal editing operations have an equivalent in vi that does the job more simply. Obviously, you will use dw or dd to delete a single word or line rather than using the delete command in ex. However, when you want to make changes that affect numerous lines, you will find the ex commands more useful. They allow you to modify large blocks of text with a single command.

These ex commands are listed here, along with abbreviations for those commands. Remember that in vi, each ex command must be preceded with a colon. You can use the full command name or the abbreviation, whichever is easier to remember.

Full nameAbbreviationMeaning
deletedDelete lines
movemMove lines
copycoCopy lines
 tCopy lines (a synonym for co)

You can separate the different elements of an ex command with spaces, if you find the command easier to read that way. For example, you can separate line addresses, patterns, and commands in this way. You cannot, however, use a space as a separator inside a pattern or at the end of a substitute command.

Line Addresses

For each ex editing command, you have to tell ex which line number(s) to edit. And for the exmove and copy commands, you also need to tell ex where to move or copy the text to.

You can specify line addresses in several ways:

  • With explicit line numbers

  • With symbols that help you specify line numbers relative to your current position in the file

  • With search patterns as addresses that identify the lines to be affected ...

The best content for your career. Discover unlimited learning on demand for around $1/day.