Online Book Reader

Home Category

Running Linux, 5th Edition - Matthias Kalle Dalheimer [356]

By Root 1198 0
the cursor to a move operation, such as $ or G. (dG deletes text from the cursor to the end of the file.) Many other commands operate on text through a move command in the same way. Using marks, you can operate on any region of text.

As we mentioned before, vi is just a text editor; it doesn't have facilities for spell checking text, compiling programs, and other such features. However, vi executes other programs that you can use to extend the editor. The command:

:x,y!command

executes the named command with the text on lines x through y as standard input, and replaces the lines with the standard output of the command. As with the s (search and replace) command, other specifications, such as % and $, can be used for the line numbers.

For example, let's say you want to prepend a quote character to all the lines in a region of text. One way to do this is to write a short shell or Perl script (see "Programming Languages and Utilities" in Chapter 1) that reads lines of input and outputs those same lines with the quote character prepended. (Or use a sed command — there are many alternatives.) You can then send lines of text through this filter, which replaces them with the quoted text within vi. If the script is called quote, just use a command such as:

:`a,.!quote

which quotes the region of text between the cursor location and the mark a.

Be familiar with the various ex-mode commands that are available. The :set command allows you to set various options; for example, :set ai turns on auto indentation of text. (:set noai turns it off.)

You can specify ex-mode commands (such as :set) to execute when starting up vi in the file .exrc in your home directory. (The name of this file can be changed with the EXINIT environment variable.) For example, your .exrc file might contain:

set ai

to turn on auto indentation. You don't need the : before ex commands in this file.

A number of good tutorials and references for vi are available—both online as well as in print. Learning the vi Editor is a good place to look for more information. One popular web site for vi information is The vi Lovers Home Page, http://thomer.com/vi/vi.html. The home of vim on the Web is http://www.vim.org.

The (X)Emacs Editor

Text editors are among the most important applications in the Unix world. They are used so often that many people spend more time within an editor than anywhere else on their Unix system. The same holds true for Linux.

The choice of an editor can be a religious one. Many editors exist, but the Unix community has arranged itself into two major groups: the Emacs camp and the vi camp. Because of vi's somewhat nonintuitive user interface, many people (newcomers and seasoned users alike) prefer Emacs over vi. However, long-time users of vi (and single-finger typists) use it more efficiently than a more complex editor such as Emacs.

If vi is one end of the text-editor spectrum, Emacs is the other; they are widely different in their design and philosophy. Emacs is partly the brainchild of Richard Stallman, founder of the Free Software Foundation and author of much of the GNU software.

Emacs is a very large system with more features than any single Unix application to date (some people would even go so far as not to call it an editor but an "integrated environment"). It contains its own LISP language engine that you can use to write extensions for the editor. (Many of the functions within Emacs are written in Emacs LISP.) Emacs includes extensions for everything from compiling and debugging programs to reading and sending electronic mail to X Window System support and more. Emacs also includes its own online tutorial and documentation. The book Learning GNU Emacs by Debra Cameron, James Elliott, Marc Loy, Eric S. Raymond, and Bill Rosenblatt (O'Reilly) is a popular guide to the editor.

Most Linux distributions include two variants of Emacs. GNU Emacs is the original version, which is still being developed, but development seems to have slowed down. XEmacs is larger, but much more user-friendly and better integrated with

Return Main Page Previous Page Next Page

®Online Book Reader