Unix Power ToolsUnix Power ToolsSearch this book

Chapter 17. vi Tips and Tricks


The vi Editor: Why So Much Material?
What We Cover
Editing Multiple Files with vi
Edits Between Files
Local Settings for vi
Using Buffers to Move or Copy Text
Get Back What You Deleted with Numbered Buffers
Using Search Patterns and Global Commands
Confirming Substitutions in vi
Keep Your Original File, Write to a New File
Saving Part of a File
Appending to an Existing File
Moving Blocks of Text by Patterns
Useful Global Commands (with Pattern Matches)
Counting Occurrences; Stopping Search Wraps
Capitalizing Every Word on a Line
Per-File Setups in Separate Files
Filtering Text Through a Unix Command
vi File Recovery Versus Networked Filesystems
Be Careful with vi -r Recovered Buffers
Shell Escapes: Running One UnixCommand While Using Another
vi Compound Searches
vi Word Abbreviation
Using vi Abbreviations as Commands (Cut and Paste Between vi's)
Fixing Typos with vi Abbreviations
vi Line Commands Versus Character Commands
Out of Temporary Space? Use Another Directory
Neatening Lines
Finding Your Place with Undo
Setting Up vi with the .exrc File

17.1. The vi Editor: Why So Much Material?

We're giving a lot of pages to the vi editor. People who use another editor, like Emacs, might wonder why. Here's why.

I've watched people (including myself) learn and use vi for 20 years. It's the standard editor that comes with almost every Unix system these days, but most people have no idea that vi can do so much. People are surprised, over and over, when I show them features that their editor has. Even with its imperfections, vi is a power tool. If you work with files, you probably use it constantly. Knowing how to use it well will save you lots of time and work.

But why not give the same coverage to another editor that lots of people use: GNU Emacs (Section 19.1)? That's because GNU Emacs comes with source code and can be extended by writing LISP code. Its commands have descriptive names that you can understand by reading through a list. vi's commands are usually no more than a few characters long; many of the option names are short and not too descriptive either. Lots of Unix systems don't even have vi source code these days.

I hope that you vi users will learn a lot in this section and that people who don't use vi will at least browse through to see some of vi's less obvious features.

If you're looking for additional text-editing power, you can use vim instead of the plain vanilla vi installed on most systems. All vi commands work with vim, but with added functionality, power, and more standardized behavior accross flavors of Unix. There should be an installation of vim for your Unix.

--JP and SP

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.