Creating and editing files are likely the most common tasks you'll perform in Unix. If you're programming, developing Web pages, sending email (uh-huh, really), or just writing a letter, you'll spend a lot of time in an editor.

In this chapter, we'll introduce you to three of the most common editors: pico (and nano comes along for free), vi, and emacs. We'll launch this chapter with a general overview of each, and then discuss some how-tos of using each one. With the information presented here, you'll be able to choose an editor based on your needs and get started using it (or using all of them).

Choosing an Editor

Basically, all editors are designed to do the same things: enable you to create, modify, and save text files. These files could include configuration files, email messages, or shell scripts—essentially any text file you can create. Exactly which editor you choose is up to you, depending on your specific needs and how much you're willing to learn.

In this book, we'll stick to three biggies—pico, vi, and emacs—which will likely give you all the capabilities you'll need. We chose these because pico is (arguably) the easiest Unix editor to use, vi is one of the most powerful and is available on almost every Unix system, and emacs provides an unbelievable number of options and is a handy tool for the up-and-coming Unix pro to have.

About pico

pico is one of the more straightforward Unix editors and has become quite popular because it's extremely easy to use. In particular, as shown in Figure 4.1, it's menu-driven and intuitive. All of the commands are visible, and you can open, modify, and close files with little effort. pico is a great choice if you're just getting started with Unix or if you won't be needing an editor able to leap tall files in a single bound.

Figure 4.1pico offers onscreen command reminders to make it easier to use.

For a variety of reasons, mostly connected to open source licensing issues, a clone of pico, called nano, has been developed and is included in a number of Linux/Unix distributions as well as on systems that you might be using. The nano editor is command-for-command the same as pico, but it does offer some supplemental higher-end (yet still easy-to-use) features.

Editors Abound

By the way, dozens of other editors exist, such as

ed, ex, and red, which are simple (in functionality, but not necessarily usage) line-by-line editors

joe and jed, which are fairly simple editors and comparable to pico in many ways

For the purposes of this book, we're going to treat pico and nano as equivalent—if you have nano, just mentally write that in wherever you see pico.

pico is distributed with the pine email program, so if you have pine available to you, you likely also have pico. (See Chapter 1 for a reminder on how to find out if pine and pico are available to you.) If pico is not available to you, and if you cannot find nano either, ask your system administrator to install one or the other.

About vi

Although vi is likely responsible for much of Unix's reputation for being complicated and confusing, it offers enormous power and flexibility. Plus, vi is universally available (unlike pico), so for these two reasons, you should consider taking the time to learn it. You might find vi cryptic, counterintuitive, and nitpicky, and for this reason, you might want to choose a different editor if you won't require vi's capabilities. As Figure 4.2 shows, if you use vi, you won't have menus at your disposal—you'll have to get used to using commands like :q or :%s/vi is arcane/vi is powerful/.

Figure 4.2vi gives you a clean screen and makes you remember all of its cryptic commands.

Yes, continuing the theme from a couple of paragraphs ago, there is an equivalent of vi, called vim, that's licensed differently and that's somewhat more powerful. For basic use—everything in this book and far more—the two are identical. In this case, though, you will always find vi, even if it's really vim (vi may actually be a symlink, or shortcut, to vim). If you find vim, though, it will assuredly be vim. All commands will be the same, so just dive in and enjoy.

About emacs

With emacs, you start to understand how incredibly customizable Unix can be. It can be "just" an editor—although a very powerful one with all kinds of helpful features—or it can be an email program, file manager, or darn near anything else. We're going to stick to just the editorial functions, but if you find that you like emacs, don't hesitate to explore the Web for other options and features of this editor. Figure 4.3 shows you what to expect from emacs, including the handy (and fairly familiar) menus.

You aren't bound to one editor or another. You can use any editor at any time. We often use pico for email or plain writing because we can type without thinking. We switch to vi when we really need power or just want to make a quick edit without pico's menus, which often seem cumbersome to us.

You can specify a default editor that will launch automatically in programs that start up an editor for you. Chapter 8 provides details about setting your editor environment variable.

See Chapter 8 for more information about configuration files, Chapter 10 for more about shell scripts, and Chapter 11 for more about email.

If you type pico and get an error message telling you that the command is not found, use find, whereis, or ls to search through the likely directories (/usr/bin or /usr/local/bin) to see whether the program is available but not located where your shell can find it. See Chapter 1 for a quick review.

After you establish a file and start adding content, save your changes using the instructions in the next section.

You can get helpful information about pico's features by accessing pico help. See the section called "Getting Help in pico," later in this chapter.