Section 4.1. Editors

   


4.1. Editors

Unix developers have traditionally held strong and diverse preferences, especially about editors.

Many programmers' editors are available for you to try; the two most common are vi and Emacs. Both have more power than they appear to have at first glance, both have a relatively steep learning curve and they are radically different. Emacs is large; it is really an operating environment of its own. vi is small and is designed to be one piece of the Unix environment. Many clones and alternative versions of each editor have been written, and each has its own following.

Tutorials on vi and Emacs would take far too much space to include in this book. The excellent A Practical Guide to Red HatR LinuxR 8 [Sobell, 2002] includes a detailed chapter on each editor. O'Reilly has published an entire book on each editor: Learning GNU Emacs [Cameron, 1996] and Learning the vi Editor [Lamb, 1990]. Here, we compare only Emacs and vi and tell you how to get online help for each.

Emacs includes a comprehensive set of manuals that explains not only how to use Emacs as an editor, but also how to use Emacs to read and send email and Usenet news, to play games (its gomoku game is not bad), and to run shell commands. In Emacs, you can always execute internal Emacs commands, even those commands that are not bound to keys, by typing the entire name of the command.

In contrast, the documentation available for vi is less generous and less well known. It is exclusively an editor, and many powerful commands are bound to single keystrokes. You switch back and forth between a mode in which typing standard alphabetic characters causes them to be inserted in your document and a mode in which those alphabetic characters are commands; for example, you can use the h, j, k, and l keys as arrow keys to navigate your document.

Both editors allow you to create macros to make your work easier, but their macro languages could hardly be more different. Emacs has a complete programming language called elisp (Emacs Lisp), which is closely related to the Common Lisp programming language. The original vi has a more spartan, stack-based language. Most users merely map keys to simple, one-line vi commands, but those commands often execute programs outside vi to manipulate data within vi. Emacs Lisp is documented in a huge manual that includes a tutorial; documentation for the original vi's language is relatively sparse.

Some editors allow you to mix and match functionality. You can use Emacs in a vi mode(called viper) that allows you to use the standard vi commands, and one of the vi clones is called vile "vi like Emacs."

4.1.1. Emacs

Emacs comes in several flavors. The original Emacs editor was written by Richard Stallman, of Free Software Foundation fame. For years, his GNU Emacs has been the most popular version. Recently, a more graphic-environment-aware variant of GNU Emacs, called XEmacs, has also become popular. XEmacs started life as Lucid Emacs, a set of enhancements to GNU Emacs managed by the now-defunct Lucid Technologies that was intended to be folded back into the official GNU Emacs. Technical differences prevented the teams from merging their code. The two editors remain highly compatible, however, and programmers on both teams regularly borrow code from each other. Because these versions are so similar, we refer to both of them as Emacs.

The best way to become comfortable with the Emacs editor is to follow its tutorial. Run emacs and type ^h t (think "control-help, tutorial"). Type ^x^c to exit Emacs. The tutorial will teach you how to get more information on Emacs. It will not teach you how to get at the Emacs manual that is distributed with Emacs. For that, use ^h i (control-help, info).

Although its user interface may not be as flashy as those of a graphical IDE, Emacs does have powerful features that many programmers want. When you use Emacs to edit C code, for example, Emacs recognizes the file type and enters "C mode," in which it recognizes C's syntax and helps you to recognize typos. When you run the compiler from within Emacs, it will recognize error and warning messages, and take you straight to the line at which each error was found when you type a single command, even if it has to read in a new file. It also provides a debugging mode that keeps the debugger in one window and follows the code you are debugging in another window.

4.1.2. vi

If you are a touch typist and like to keep your fingers on the home row,[1] you may appreciate vi, because its command set was designed to minimize finger movement for touch typists. It was also designed for Unix users; if you are familiar with sed or awk or other Unix programs that use standard regular expressions, using ^ to go to the beginning of a line and $ to go to the end of one will feel perfectly natural.

[1] If you are a qwerty touch typist, that is. Dvorak touch typists who use vi generally use lots of vi macros to make vi comfortable for them.

Unfortunately, vi can be harder to learn than Emacs because, although there are vi tutorials similar to the standard Emacs tutorial available, there is no standard way to execute the tutorial from any version of vi. However, most versions, including versions shipped with common Linux distributions, support the :help command.

The most common version of vi, vim ("Vi IMproved"), has many of the features integrating development tools provided by Emacs, including syntax highlighting, automatic indentation, an expressive scripting language, and compiler error parsing.


       
    top
     


    Linux Application Development
    Linux Application Development (paperback) (2nd Edition)
    ISBN: 0321563220
    EAN: 2147483647
    Year: 2003
    Pages: 168

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net