Learning the vi and Vim Editors, 8th Edition

Book description

Among the text editors being used in the programming community, perhaps the most important family is vi and its derivatives. With this updated edition, Unix and Linux users will learn text editing basics for both vi and Vim ("vi improved") before moving on to advanced editing tools for each editor. Authors Arnold Robbins and Elbert Hannah cover the latest major releases of Vim, including 8.0 and 8.2.

If you're a programmer or computer analyst, or you work with browsers or command-line interfaces, using Vim can speed up your work and make complex tasks easier. You'll examine multiwindow editing, global search and replacement, and power tools for programmers, and learn how to write interactive macros and scripts to extend the editor--all in the easy-to-follow style that's made this book a classic.

  • Go beyond the basics to learn which vi commands fit your specific needs
  • Learn advanced vi tools that shift most of the editing burden to the computer
  • Explore Vim tools that provide major improvements over vi
  • Examine Vimâ??s multiwindow editing feature, a significant upgrade over vi
  • Use Vim scripts to customize and tailor Vim to your needs
  • Look at Vim in modern GUI environments with Graphical Vim (gvim)
  • See Vim in the broader programming milieu, including usingit as an IDE

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Scope of This Book
    2. How the Material Is Presented
      1. Discussion of vi Commands
      2. Conventions
      3. Keystrokes
      4. Cautions, Notes, and Tips
      5. Problem Checklists
    3. What You Need to Know Before Starting
    4. Using Code Examples
    5. O’Reilly Online Learning
    6. How to Contact Us
    7. About the Previous Editions
    8. About the Eighth Edition
      1. What’s New
      2. Versions
    9. Acknowledgments from the Sixth Edition
    10. Acknowledgments from the Seventh Edition
    11. Acknowledgments for the Eighth Edition
  2. I. vi and Vim Fundamentals
  3. 1. Introducing vi and Vim
    1. Text Editors and Text Editing
      1. Text Editors
      2. Text Editing
    2. A Brief Historical Perspective
    3. Opening and Closing Files
      1. Opening a File from the Command Line
      2. Opening a File from the GUI
      3. Problems Opening Files
      4. Modus Operandi
      5. Saving and Quitting a File
    4. Quitting Without Saving Edits
      1. Problems Saving Files
      2. Exercises
  4. 2. Simple Editing
    1. vi Commands
    2. Moving the Cursor in Command Mode
      1. Single Movements
      2. Numeric Arguments
      3. Movement Within a Line
      4. Movement by Text Blocks
    3. Simple Edits
      1. Inserting New Text
      2. Appending Text
      3. Changing Text
      4. Changing Case
      5. Deleting Text
      6. Moving Text
      7. Copying Text
      8. Repeating or Undoing Your Last Command
    4. More Ways to Insert Text
      1. Numeric Arguments for Insert Commands
    5. Joining Two Lines with J
      1. Problems with vi Commands
    6. Mode Indicators
    7. Review of Basic vi Commands
  5. 3. Moving Around in a Hurry
    1. Movement by Screens
      1. Scrolling the Screen
      2. Repositioning the Screen with z
      3. Redrawing the Screen
      4. Movement Within a Screen
      5. Movement by Line
    2. Movement by Text Blocks
    3. Movement by Searches
      1. Repeating Searches
      2. Current Line Searches
    4. Movement by Line Number
      1. The G (Go To) Command
    5. Review of vi Motion Commands
  6. 4. Beyond the Basics
    1. More Command Combinations
    2. Options When Starting vi and Vim
      1. Advancing to a Specific Place
      2. Read-Only Mode
      3. Recovering a Buffer
    3. Making Use of Registers
      1. Recovering Deletions
      2. Yanking to Named Registers
    4. Marking Your Place
    5. Other Advanced Edits
    6. Review of Register and Marking Commands
  7. 5. Introducing the ex Editor
    1. ex Commands
      1. Exercise: The ex Editor
      2. Problem Getting to Visual Mode
    2. Editing with ex
      1. Line Addresses
      2. Defining a Range of Lines
      3. Line-Addressing Symbols
      4. Search Patterns
      5. Redefining the Current Line Position
      6. Global Searches
      7. Combining ex Commands
    3. Saving and Exiting Files
      1. Renaming the Buffer
      2. Saving Part of a File
      3. Appending to a Saved File
    4. Copying a File into Another File
    5. Editing Multiple Files
      1. Invoking Vim on Multiple Files
      2. Using the Argument List
      3. Calling in New Files
      4. Filename Shortcuts
      5. Switching Files from Command Mode
      6. Edits Between Files
    6. ex Command Summaries
  8. 6. Global Replacement
    1. The Substitute Command
    2. Confirming Substitutions
    3. Doing Things Globally Across the File
    4. Context-Sensitive Replacement
    5. Pattern-Matching Rules
      1. Metacharacters Used in Search Patterns
      2. POSIX Bracket Expressions
      3. Metacharacters Used in Replacement Strings
      4. More Substitution Tricks
    6. Pattern-Matching Examples
      1. Search for General Class of Words
      2. Block Move by Patterns
      3. More Examples
    7. A Final Look at Pattern Matching
      1. Deleting an Unknown Block of Text
      2. Switching Items in a Textual Database
      3. Using :g to Repeat a Command
      4. Collecting Lines
  9. 7. Advanced Editing
    1. Customizing vi and Vim
      1. The :set Command
      2. The .exrc File
      3. Alternate Environments
      4. Some Useful Options
    2. Executing Unix Commands
      1. Filtering Text Through a Command
    3. Saving Commands
      1. Word Abbreviation
      2. Using the map Command
      3. Mapping with a Leader
      4. Protecting Keys from Interpretation by ex
      5. A Complex Mapping Example
      6. More Examples of Mapping Keys
      7. Mapping Keys for Insert Mode
      8. Mapping Function Keys
      9. Mapping Other Special Keys
      10. Mapping Multiple Input Keys
      11. @-Functions
      12. Executing Registers from ex
    4. Using ex Scripts
      1. Looping in a Shell Script
      2. Here Documents
      3. Sorting Text Blocks: A Sample ex Script
      4. Comments in ex Scripts
      5. Beyond ex
    5. Editing Program Source Code
      1. Indentation Control
      2. A Special Search Command
      3. Using Tags
      4. Enhanced Tags
  10. II. Vim
  11. 8. Vim (vi Improved): Overview and Improvements over vi
    1. About Vim
    2. Overview
      1. Author and History
      2. Why Vim?
      3. Compare and Contrast with vi
      4. Categories of Features
      5. Philosophy
    3. Aids and Easy Modes for New Users
    4. Built-In Help
    5. Startup and Initialization Options
      1. Command-Line Options
      2. Behaviors Associated to Command Name
      3. System and User Configuration Files
      4. Environment Variables
    6. New Motion Commands
      1. Visual Mode Motion
    7. Extended Regular Expressions
    8. Extended Undo
    9. Incremental Searching
    10. Left-Right Scrolling
    11. Summary
  12. 9. Graphical Vim (gvim)
    1. General Introduction to gvim
      1. Starting gvim
      2. Using the Mouse
      3. Useful Menus
    2. Customizing Scrollbars, Menus, and Toolbars
      1. Scrollbars
      2. Menus
      3. Toolbars
      4. Tooltips
    3. gvim in Microsoft Windows
    4. gvim in the X Window System
    5. Running gvim in Microsoft Windows WSL
      1. Installing gvim in WSL 2
      2. Installing an X Server for Windows
      3. Configuring the X Server for Windows
    6. GUI Options and Command Synopsis
  13. 10. Multiple Windows in Vim
    1. Initiating Multiwindow Editing
      1. Multiwindow Initiation from the Command Line
      2. Multiwindow Editing Inside Vim
    2. Opening Windows
      1. New Windows
      2. Options During Splits
      3. Conditional Split Commands
      4. Window Command Summary
    3. Moving Around Windows (Getting Your Cursor from Here to There)
    4. Moving Windows Around
      1. Moving Windows (Rotate or Exchange)
      2. Moving Windows and Changing Their Layout
      3. Window Move Commands: Synopsis
    5. Resizing Windows
      1. Window Resize Commands
      2. Window Sizing Options
      3. Resizing Command Synopsis
    6. Buffers and Their Interaction with Windows
      1. Vim’s Special Buffers
      2. Hidden Buffers
      3. Buffer Commands
      4. Buffer Command Synopsis
    7. Playing Tag with Windows
    8. Tabbed Editing
    9. Closing and Quitting Windows
    10. Summary
  14. 11. Vim Enhancements for Programmers
    1. Folding and Outlining (Outline Mode)
      1. The Fold Commands
      2. Manual Folding
      3. Outlining
      4. A Few Words About the Other Fold Methods
    2. Auto and Smart Indenting
      1. Vim autoindent Extensions to vi’s autoindent
      2. smartindent
      3. cindent
      4. indentexpr
      5. A Final Word on Indentation
    3. Keyword and Dictionary Word Completion
      1. Insertion Completion Commands
      2. Some Final Comments on Vim Autocompletion
    4. Tag Stacking
    5. Syntax Highlighting
      1. Getting Started
      2. Customization
      3. Rolling Your Own
    6. Compiling and Checking Errors with Vim
      1. More Uses for the Quickfix List Window
    7. Some Final Thoughts on Vim for Writing Programs
  15. 12. Vim Scripts
    1. What’s Your Favorite Color (Scheme)?
      1. Conditional Execution
      2. Variables
      3. The execute Command
      4. Defining Functions
      5. A Nice Vim Piggybacking Trick
      6. Tuning a Vim Script with Global Variables
      7. Arrays
    2. Dynamic File Type Configuration Through Scripting
      1. Autocommands
      2. Checking Options
      3. Buffer Variables
      4. The exists() Function
      5. Autocommands and Groups
      6. Deleting Autocommands
    3. Some Additional Thoughts About Vim Scripting
      1. A Useful Vim Script Example
      2. More About Variables
      3. Expressions
      4. Extensions
      5. A Few More Comments About autocmd
      6. Internal Functions
    4. Resources
  16. 13. Other Cool Stuff in Vim
    1. Spell It! (i-t)
      1. For a Different Take on Words, Try Thesaurus
    2. Editing Binary Files
    3. Digraphs: Non-ASCII Characters
    4. Editing Files in Other Places
    5. Navigating and Changing Directories
    6. Backups with Vim
    7. HTML Your Text
    8. What’s the Difference?
    9. viminfo: Now, Where Was I?
      1. The viminfo Option
      2. The mksession Command
    10. What’s My Line (Size)?
    11. Abbreviations of Vim Commands and Options
    12. A Few Quickies (Not Necessarily Vim-Specific)
    13. More Resources
  17. 14. Some Vim Power Techniques
    1. Several Convenience Maps
      1. Exiting Vim Simplified
      2. Resize Your Window
      3. Double Your Fun
    2. Moving into the Fast Lane
      1. Finding a Hard-to-Remember Command
      2. Analyzing a Famous Speech
      3. Some More Use Cases
    3. Hitting the Speed Limit
    4. Enhancing the Status Line
    5. Summary
  18. III. Vim in the Larger Milieu
  19. 15. Vim as IDE: Some Assembly Required
    1. Plug-In Managers
    2. Finding Just the Right Plug-In
    3. Why Do We Want an IDE?
    4. Doing It Yourself
      1. EditorConfig: Consistent Text Editing Setup
      2. NERDTree: File Tree Traversal Within Vim
      3. nerdtree-git-plug-in: NERDTree with Git Status Indicators
      4. Fugitive: Running Git from Within Vim
      5. Completion
      6. Termdebug: Use GDB Directly Within Vim
    5. All-in-One IDEs
    6. Coding Is Great, but What If I’m a Writer?
    7. Conclusion
  20. 16. vi Is Everywhere
    1. Introduction
    2. Improving the Command-Line Experience
    3. Sharing Multiple Shells
    4. The readline Library
      1. The Bash Shell
      2. Other Programs
      3. The .inputrc File
    5. Other Unix Shells
      1. The Z Shell (zsh)
      2. Keep As Much History As You Can
      3. Command-Line Editing: Some Closing Thoughts
    6. Windows PowerShell
    7. Developer Tools
      1. The Clewn GDB Driver
      2. CGDB: Curses GDB
      3. Vim Inside Visual Studio
      4. Vim for Visual Studio Code
    8. Unix Utilities
      1. More or Less?
      2. screen
    9. And …, Browsers!
      1. Wasavi
      2. Vim + Chromium = Vimium
    10. vi for MS Word and Outlook
    11. Honorable Mention: Tools with Some vi Features
      1. Google Mail
      2. Microsoft PowerToys
    12. Summary
  21. 17. Epilogue
  22. IV. Appendixes
  23. A. The vi, ex, and Vim Editors
    1. Command-Line Syntax
      1. Command-Line Options
    2. Review of vi Operations
      1. Command Mode
      2. Insert Mode
      3. Syntax of vi Commands
      4. Status-Line Commands
    3. vi Commands
      1. Movement Commands
      2. Insert Commands
      3. Edit Commands
      4. Saving and Exiting
      5. Accessing Multiple Files
      6. Window Commands (Vim)
      7. Interacting with the System
      8. Macros
      9. Miscellaneous Commands
    4. vi Configuration
      1. The :set Command
      2. Example .exrc File
    5. ex Basics
      1. Syntax of ex Commands
      2. Addresses
      3. Address Symbols
      4. Options
    6. Alphabetical Summary of ex Commands
  24. B. Setting Options
    1. Heirloom and Solaris vi Options
    2. Vim 8.2 Options
  25. C. The Lighter Side of vi
    1. Accessing the Files
      1. Example Files
      2. Source for clewn
    2. Online vi Tutorial
    3. vi Powered!
    4. vi for Java Lovers
    5. The Vim Clutch
    6. Amaze Your Friends!
    7. The Vi Lovers Home Page
    8. A Different vi Clone
    9. Tastes Great, Less Filling
    10. vi Quotes
  26. D. vi and Vim: Source Code and Building
    1. Nothing Like the Original
    2. Where to Get Vim
      1. Getting Vim for Unix and GNU/Linux
      2. Getting Vim for Windows Environments
      3. Getting Vim for the Macintosh Environment
      4. Other Operating Systems
  27. Index
  28. About the Authors

Product information

  • Title: Learning the vi and Vim Editors, 8th Edition
  • Author(s): Arnold Robbins, Elbert Hannah
  • Release date: November 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492078807