O'Reilly logo

Mac OS X in a Nutshell by Chris Stone, Chuck Toporek, Jason McIntosh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unix Text Editors

For years, two text editors have held equal sway in Unix culture: vi and Emacs. Not one to take sides, Mac OS X ships with both of them. The following two sections give you a whirlwind tour of both.

Tip

You don’t have to use one of these editors in order to open a text document from a Terminal window. You can instead use the open command with its -a (application-specifying) option to send the document to an Aqua text editor, such as TextEdit, like this:

% open -a TextExit 
                  somefile.txt

vi

vi is a modal editor, signifying that the meaning of what you type at any point depends entirely on what mode (context) the program is in. vi’s modes include command mode (see Section 17.4.1.2), which performs deletion, cut-and-paste, searching, and other text-editing commands, and insertion mode, which adds new text to the document through typing.

Command-line syntax

The three most common ways of starting a vi session are:

  • vi file

  • vi + line-number file

  • vi +/ pattern file

You can open file for editing, optionally at line n or at the first line matching pattern. (See Chapter 20 for more on pattern matching.) If no file is specified, vi opens with an empty buffer. See Chapter 25 for more information on command-line options for vi.

Command mode

Once the file is opened, you are in command mode. From here, you can:

  • Invoke an insert mode

  • Issue editing commands

  • Move the cursor to a different position in the file

  • Invoke ex commands

  • Invoke a Unix shell

  • Save or exit the current version of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required