- Choosing an Editor
- Starting pico and Dabbling with It
- Saving in pico
- Cutting and Pasting Text Blocks in pico
- Checking Spelling in pico
- Getting Help in pico
- Exiting pico
- Starting vi and Dabbling with It
- Saving in vi
- Adding and Deleting Text in vi
- Importing Files into vi
- Searching and Replacing in vi
- Exiting vi
- Starting emacs and Dabbling with It
- Using emacs Menus to Spell-Check
- Saving in emacs
- Exiting emacs
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.
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.1 pico 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.
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.
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.2 vi 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.
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.
Figure 4.3 emacs provides both menus and power, all at once.